first commit
This commit is contained in:
10
src/Define.h
Normal file
10
src/Define.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef Define_h
|
||||
#define Define_h
|
||||
//#define DebugCalibration
|
||||
//#define DINBIAO
|
||||
//#define Curentvsion "V2.4b"\
|
||||
#define Curentvsion "V2.5b"
|
||||
#define Curentvsion "V2.3"
|
||||
#define TINY_GSM_DEBUG Serial
|
||||
|
||||
#endif
|
||||
136
src/GSMMannager.cpp
Normal file
136
src/GSMMannager.cpp
Normal file
@ -0,0 +1,136 @@
|
||||
#include "GSMMannager.h"
|
||||
HardwareSerial *MySerial;
|
||||
GSMMannger::GSMMannger(int serialnumber, int rx, int tx)
|
||||
{
|
||||
MySerial=new HardwareSerial(serialnumber);
|
||||
modem = new TinyGsm(*MySerial);
|
||||
MySerial->begin(115200, SERIAL_8N1, rx, tx);
|
||||
client = new TinyGsmClient(*modem);
|
||||
// !!!!!!!!!!! <20>ϵ<EFBFBD>
|
||||
Serial.println("Wait...");
|
||||
pinMode(37, OUTPUT); //pin32控制sim800C电源 高电平上电 低电平断电
|
||||
digitalWrite(37, HIGH);
|
||||
delay(100);
|
||||
digitalWrite(37, LOW);
|
||||
Serial.println("Wait...1");
|
||||
delay(1800);
|
||||
// Set your reset, enable, power pins here
|
||||
// !!!!!!!!!!!
|
||||
|
||||
delay(5000);
|
||||
// Set GSM module baud rate
|
||||
// MySerial->readString();
|
||||
int banddd=TinyGsmAutoBaud(*MySerial, rx, tx, 9600,460800);
|
||||
if (banddd==0)
|
||||
{
|
||||
Serial.println("fail to connect sim800 reboot");
|
||||
esp_restart();
|
||||
/* code */
|
||||
}
|
||||
|
||||
Serial.println("band is" + String(banddd));
|
||||
delay(6000);
|
||||
modem->init();
|
||||
|
||||
String modemInfo = modem->getModemInfo();
|
||||
if (modemInfo=="")
|
||||
{
|
||||
Serial.println("fail to getmode reboot");
|
||||
esp_restart();
|
||||
/* code */
|
||||
}
|
||||
Serial.print("Modem Info: ");
|
||||
|
||||
SerialMon.println(modemInfo);
|
||||
if (GSM_PIN && modem->getSimStatus() != 3)
|
||||
{
|
||||
modem->simUnlock(GSM_PIN);
|
||||
}
|
||||
SerialMon.print("Waiting for network...");
|
||||
if (!modem->waitForNetwork())
|
||||
{
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" success");
|
||||
|
||||
if (modem->isNetworkConnected())
|
||||
{
|
||||
SerialMon.println("Network connected");
|
||||
}
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(apn);
|
||||
if (!modem->gprsConnect(apn, gprsUser, gprsPass))
|
||||
{
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" success");
|
||||
|
||||
if (modem->isGprsConnected())
|
||||
{
|
||||
SerialMon.println("GPRS connected");
|
||||
}
|
||||
modem->NTPServerSync();
|
||||
}
|
||||
String GSMMannger::I2toS(int n)
|
||||
{
|
||||
if (n>=10)
|
||||
{
|
||||
return String(n);
|
||||
} else{
|
||||
return "0"+ String(n);
|
||||
}
|
||||
}
|
||||
String GSMMannger::GetDataAndTime() {
|
||||
//String str=modem->getGSMDateTime(DATE_FULL);
|
||||
if(modem->getNetworkTime(&year,&month,&day,&hour,&minute, &second,&timezone))
|
||||
{
|
||||
String date=String(year)+"-"+I2toS(month)+"-"+I2toS(day)+" "+I2toS(hour)+":"+I2toS(minute)+":"+I2toS(second);
|
||||
return date;}
|
||||
return "2000-01-01 00:00:00";
|
||||
}
|
||||
|
||||
void GSMMannger::loop()
|
||||
{
|
||||
|
||||
if (!modem->isNetworkConnected())
|
||||
{
|
||||
|
||||
SerialMon.println("Network disconnected");
|
||||
if (!modem->waitForNetwork(20000L, true))
|
||||
{
|
||||
SerialMon.println(" re wait For Network fail");
|
||||
esp_restart();
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
if (modem->isNetworkConnected())
|
||||
{
|
||||
SerialMon.println("Network re-connected");
|
||||
}
|
||||
|
||||
// and make sure GPRS/EPS is still connected
|
||||
if (!modem->isGprsConnected())
|
||||
{
|
||||
SerialMon.println("GPRS disconnected!");
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(apn);
|
||||
if (!modem->gprsConnect(apn, gprsUser, gprsPass))
|
||||
{
|
||||
SerialMon.println(" set apn gprsuser gprspass fail");
|
||||
esp_restart();
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
if (modem->isGprsConnected())
|
||||
{
|
||||
SerialMon.println("GPRS reconnected");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
33
src/GSMMannager.h
Normal file
33
src/GSMMannager.h
Normal file
@ -0,0 +1,33 @@
|
||||
#define TINY_GSM_MODEM_SIM800
|
||||
#define SerialMon Serial
|
||||
#include <TinyGsmClient.h>
|
||||
#include <PubSubClient.h>
|
||||
|
||||
|
||||
//#define TINY_GSM_DEBUG SerialMon
|
||||
#define GSM_AUTOBAUD_MIN 9600
|
||||
#define GSM_AUTOBAUD_MAX 115200
|
||||
#define TINY_GSM_USE_GPRS true
|
||||
#define TINY_GSM_USE_WIFI false
|
||||
|
||||
#define GSM_PIN ""
|
||||
|
||||
const char apn[] = "CMNET";
|
||||
const char gprsUser[] = "";
|
||||
const char gprsPass[] = "";
|
||||
|
||||
class GSMMannger
|
||||
{
|
||||
public:
|
||||
GSMMannger(int serialnumber,int rx,int tx); // <20><><EFBFBD>ǹ<EFBFBD><C7B9>캯<EFBFBD><ECBAAF>
|
||||
TinyGsm *modem;
|
||||
TinyGsmClient *client;
|
||||
String GetDataAndTime();
|
||||
void loop();
|
||||
String I2toS(int n);
|
||||
int year,month, day, hour,minute, second;
|
||||
float timezone;
|
||||
|
||||
};
|
||||
|
||||
|
||||
5
src/MyEsp8266.cpp
Normal file
5
src/MyEsp8266.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by xin on 2022/4/28.
|
||||
//
|
||||
|
||||
#include "MyEsp8266.h"
|
||||
14
src/MyEsp8266.h
Normal file
14
src/MyEsp8266.h
Normal file
@ -0,0 +1,14 @@
|
||||
//
|
||||
// Created by xin on 2022/4/28.
|
||||
//
|
||||
|
||||
#ifndef ESP32MAINBOARD_MYESP8266_H
|
||||
#define ESP32MAINBOARD_MYESP8266_H
|
||||
|
||||
|
||||
class MyEsp8266 {
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //ESP32MAINBOARD_MYESP8266_H
|
||||
138
src/MyWebServer.cpp
Normal file
138
src/MyWebServer.cpp
Normal file
@ -0,0 +1,138 @@
|
||||
#include "MyWebServer.h"
|
||||
|
||||
ESPWebServer *ESPStaticServer;
|
||||
void webserver::printn(String str)
|
||||
{
|
||||
if (serialmy != nullptr)
|
||||
{
|
||||
serialmy->print(str);
|
||||
}
|
||||
}
|
||||
void webserver::initme()
|
||||
{
|
||||
|
||||
printn("webserver begain\n");
|
||||
|
||||
// wifiMulti.addAP("IRIS", "irishk*******"); // 将需要连接的一系列WiFi ID和密码输入这里
|
||||
// wifiMulti.addAP("ssid_from_AP_2", "your_password_for_AP_2"); // ESP8266-NodeMCU再启动后会扫描当前网络
|
||||
// wifiMulti.addAP("ssid_from_AP_3", "your_password_for_AP_3"); // 环境查找是否有这里列出的WiFi ID。如果有
|
||||
// printn("Connecting ..."); // 则尝试使用此处存储的密码进行连接。
|
||||
|
||||
// int i = 0;
|
||||
// while (wifiMulti.run() != WL_CONNECTED) { // 尝试进行wifi连接。
|
||||
// delay(1000);
|
||||
// printn("retry to connect wifi");
|
||||
// }
|
||||
|
||||
// WiFi连接成功后将通过串口监视器输出连接成功信息
|
||||
|
||||
printn("Connected to \n");
|
||||
printn(WiFi.SSID()); // 通过串口监视器输出连接的WiFi名称
|
||||
printn("IP address:\t");
|
||||
printn(WiFi.localIP().toString()); // 通过串口监视器输出ESP8266-NodeMCU的IP
|
||||
printn("\n");
|
||||
if (SPIFFS.begin())
|
||||
{ // 启动闪存文件系统
|
||||
printn("SPIFFS Started.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printn("SPIFFS Failed to Start.\n");
|
||||
}
|
||||
|
||||
server->onNotFound(handleUserRequet); // 告知系统如何处理用户请求
|
||||
|
||||
server->begin(); // 启动网站服务
|
||||
printn("HTTP server started\n");
|
||||
}
|
||||
webserver::webserver(HardwareSerial *serial)
|
||||
{
|
||||
serialmy = serial;
|
||||
server=new ESPWebServer(80);
|
||||
ESPStaticServer=server;
|
||||
initme();
|
||||
}
|
||||
webserver::webserver()
|
||||
{
|
||||
serialmy = nullptr;
|
||||
server=new ESPWebServer(80);
|
||||
ESPStaticServer=server;
|
||||
initme();
|
||||
}
|
||||
|
||||
webserver::~webserver()
|
||||
{
|
||||
}
|
||||
|
||||
void webserver::handleUserRequet()
|
||||
{
|
||||
Serial.println("some one come\n");
|
||||
|
||||
// 获取用户请求网址信息
|
||||
String webAddress = ESPStaticServer->uri();
|
||||
|
||||
// 通过handleFileRead函数处处理用户访问
|
||||
bool fileReadOK = handleFileRead(webAddress);
|
||||
|
||||
// 如果在SPIFFS无法找到用户访问的资源,则回复404 (Not Found)
|
||||
if (!fileReadOK)
|
||||
{
|
||||
ESPStaticServer->send(404, "text/plain", "404 Not Found");
|
||||
}
|
||||
}
|
||||
|
||||
bool webserver::handleFileRead(String path)
|
||||
{ //处理浏览器HTTP访问
|
||||
|
||||
if (path.endsWith("/"))
|
||||
{ // 如果访问地址以"/"为结尾
|
||||
path = "/index.html"; // 则将访问地址修改为/index.html便于SPIFFS访问
|
||||
}
|
||||
|
||||
String contentType = getContentType(path); // 获取文件类型
|
||||
|
||||
if (SPIFFS.exists(path))
|
||||
{ // 如果访问的文件可以在SPIFFS中找到
|
||||
File file = SPIFFS.open(path, "r"); // 则尝试打开该文件
|
||||
ESPStaticServer->streamFile(file, contentType); // 并且将该文件返回给浏览器
|
||||
file.close(); // 并且关闭文件
|
||||
return true; // 返回true
|
||||
}
|
||||
return false; // 如果文件未找到,则返回false
|
||||
}
|
||||
|
||||
// 获取文件类型
|
||||
String webserver::getContentType(String filename)
|
||||
{
|
||||
if (filename.endsWith(".htm"))
|
||||
return "text/html";
|
||||
else if (filename.endsWith(".html"))
|
||||
return "text/html";
|
||||
else if (filename.endsWith(".css"))
|
||||
return "text/css";
|
||||
else if (filename.endsWith(".js"))
|
||||
return "application/javascript";
|
||||
else if (filename.endsWith(".png"))
|
||||
return "image/png";
|
||||
else if (filename.endsWith(".gif"))
|
||||
return "image/gif";
|
||||
else if (filename.endsWith(".jpg"))
|
||||
return "image/jpeg";
|
||||
else if (filename.endsWith(".ico"))
|
||||
return "image/x-icon";
|
||||
else if (filename.endsWith(".xml"))
|
||||
return "text/xml";
|
||||
else if (filename.endsWith(".pdf"))
|
||||
return "application/x-pdf";
|
||||
else if (filename.endsWith(".zip"))
|
||||
return "application/x-zip";
|
||||
else if (filename.endsWith(".gz"))
|
||||
return "application/x-gzip";
|
||||
return "text/plain";
|
||||
}
|
||||
|
||||
void webserver::loop()
|
||||
{
|
||||
ESPStaticServer->handleClient();
|
||||
// printn("...");
|
||||
}
|
||||
38
src/MyWebServer.h
Normal file
38
src/MyWebServer.h
Normal file
@ -0,0 +1,38 @@
|
||||
#ifndef wenserver_H
|
||||
#define wenserver_H
|
||||
#define ESP32
|
||||
#ifdef ESP32
|
||||
|
||||
#include "WebServer.h"
|
||||
#include "WiFi.h"
|
||||
#include "Arduino.h"
|
||||
#include "SPIFFS.h"
|
||||
#define ESPWebServer WebServer
|
||||
#elif
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#define ESPWebServer ESP8266WebServer
|
||||
#endif
|
||||
#include <FS.h>
|
||||
|
||||
class webserver
|
||||
{
|
||||
private:
|
||||
|
||||
public:
|
||||
webserver(HardwareSerial *serial);
|
||||
webserver();
|
||||
void initme();
|
||||
HardwareSerial *serialmy;
|
||||
~webserver();
|
||||
static void handleUserRequet();
|
||||
static bool handleFileRead(String path);
|
||||
static String getContentType(String filename);
|
||||
void loop();
|
||||
void printn(String str);
|
||||
ESPWebServer *server;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
287
src/SDmanger.cpp
Normal file
287
src/SDmanger.cpp
Normal file
@ -0,0 +1,287 @@
|
||||
#include"SDmanger.h"
|
||||
File Comenfile;
|
||||
|
||||
int sdcard::init_sdcard()
|
||||
{
|
||||
SD_MMC.setPins(9,10,11,12,13,14);
|
||||
int succ = SD_MMC.begin("/sdcard", true,true,150);
|
||||
if (succ) {
|
||||
Serial.printf("SD_MMC Begin: %d\n", succ);
|
||||
uint8_t cardType = SD_MMC.cardType();
|
||||
Serial.print("SD_MMC Card Type: ");
|
||||
if (cardType == CARD_MMC) {
|
||||
Serial.println("MMC");
|
||||
} else if (cardType == CARD_SD) {
|
||||
Serial.println("SDSC");
|
||||
} else if (cardType == CARD_SDHC) {
|
||||
Serial.println("SDHC");
|
||||
} else {
|
||||
Serial.println("UNKNOWN");
|
||||
}
|
||||
|
||||
uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
|
||||
Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize);
|
||||
|
||||
} else {
|
||||
Serial.printf("Failed to mount SD card VFAT filesystem. \n");
|
||||
Serial.println("Do you have an SD Card installed?");
|
||||
Serial.println("Check pin 12 and 13, not grounded, or grounded with 10k resistors!\n\n");
|
||||
// major_fail();
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void sdcard::mylistDir( const char * dirname, uint8_t levels) {
|
||||
|
||||
Serial.printf("Listing directory: %s\n", "/");
|
||||
String dir(dirname);
|
||||
File root = SD_MMC.open(dirname);
|
||||
if (!root) {
|
||||
Serial.println("Failed to open directory");
|
||||
return;
|
||||
}
|
||||
if (!root.isDirectory()) {
|
||||
Serial.println("Not a directory");
|
||||
return;
|
||||
}
|
||||
|
||||
File filex = root.openNextFile();
|
||||
while (filex) {
|
||||
if (filex.isDirectory())
|
||||
{
|
||||
Serial.print(" DIR : ");
|
||||
Serial.println(filex.name());
|
||||
if (levels) {
|
||||
String filename=dir+"/"+String(filex.name());
|
||||
mylistDir( filename.c_str(), levels - 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print(" FILE: ");
|
||||
Serial.print(filex.name());
|
||||
Serial.print(" SIZE: ");
|
||||
Serial.println(filex.size());
|
||||
}
|
||||
filex = root.openNextFile();
|
||||
}
|
||||
}
|
||||
bool sdcard::ListDir(const char * dirname,Vector <String> &stringlist)
|
||||
{
|
||||
stringlist.clear();
|
||||
Serial.printf("Listing directory: %s\n", dirname);
|
||||
String dir(dirname);
|
||||
File root = SD_MMC.open(dirname);
|
||||
if (!root) {
|
||||
Serial.println("Failed to open directory");
|
||||
return true;
|
||||
}
|
||||
if (!root.isDirectory()) {
|
||||
Serial.println("Not a directory");
|
||||
return true;
|
||||
}
|
||||
|
||||
File filex = root.openNextFile();
|
||||
while (filex)
|
||||
{
|
||||
if (filex.isDirectory()) {
|
||||
|
||||
} else {
|
||||
String filename=dir+"/"+String(filex.name());
|
||||
stringlist.push_back(filename);
|
||||
|
||||
if (stringlist.size()==stringlist.max_size())
|
||||
{
|
||||
return false;
|
||||
/* code */
|
||||
}
|
||||
|
||||
}
|
||||
filex = root.openNextFile();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void sdcard::delete_old_stuff() {
|
||||
|
||||
Serial.printf("Total space: %lluMB\n", SD_MMC.totalBytes() / (1024 * 1024));
|
||||
Serial.printf("Used space: %lluMB\n", SD_MMC.usedBytes() / (1024 * 1024));
|
||||
|
||||
//listDir( "/", 0);
|
||||
|
||||
float full = 1.0 * SD_MMC.usedBytes() / SD_MMC.totalBytes();;
|
||||
if (full < 0.8) {
|
||||
Serial.printf("Nothing deleted, %.1f%% disk full\n", 100.0 * full);
|
||||
} else {
|
||||
Serial.printf("Disk is %.1f%% full ... deleting oldest file\n", 100.0 * full);
|
||||
while (full > 0.8) {
|
||||
|
||||
double del_number = 999999999;
|
||||
char del_numbername[50];
|
||||
|
||||
File f = SD_MMC.open("/");
|
||||
|
||||
File file = f.openNextFile();
|
||||
|
||||
while (file) {
|
||||
//Serial.println(file.name());
|
||||
if (!file.isDirectory()) {
|
||||
|
||||
char foldname[50];
|
||||
strcpy(foldname, file.name());
|
||||
for ( int x = 0; x < 50; x++) {
|
||||
if ( (foldname[x] >= 0x30 && foldname[x] <= 0x39) || foldname[x] == 0x2E) {
|
||||
} else {
|
||||
if (foldname[x] != 0) foldname[x] = 0x20;
|
||||
}
|
||||
}
|
||||
|
||||
double i = atof(foldname);
|
||||
if ( i > 0 && i < del_number) {
|
||||
strcpy (del_numbername, file.name());
|
||||
del_number = i;
|
||||
}
|
||||
//Serial.printf("Name is %s, number is %f\n", foldname, i);
|
||||
}
|
||||
file = f.openNextFile();
|
||||
|
||||
}
|
||||
Serial.printf("lowest is Name is %s, number is %f\n", del_numbername, del_number);
|
||||
if (del_number < 999999999) {
|
||||
deleteFolderOrFile(del_numbername);
|
||||
}
|
||||
full = 1.0 * SD_MMC.usedBytes() / SD_MMC.totalBytes();
|
||||
Serial.printf("Disk is %.1f%% full ... \n", 100.0 * full);
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sdcard::deleteFolderOrFile(const char * val) {
|
||||
// Function provided by user @gemi254
|
||||
Serial.printf("Deleting : %s\n", val);
|
||||
File f = SD_MMC.open(val);
|
||||
if (!f) {
|
||||
Serial.printf("Failed to open %s\n", val);
|
||||
return;
|
||||
}
|
||||
|
||||
if (f.isDirectory()) {
|
||||
File file = f.openNextFile();
|
||||
while (file) {
|
||||
if (file.isDirectory()) {
|
||||
Serial.print(" DIR : ");
|
||||
Serial.println(file.name());
|
||||
} else {
|
||||
Serial.print(" FILE: ");
|
||||
Serial.print(file.name());
|
||||
Serial.print(" SIZE: ");
|
||||
Serial.print(file.size());
|
||||
if (SD_MMC.remove(file.name())) {
|
||||
Serial.println(" deleted.");
|
||||
} else {
|
||||
Serial.println(" FAILED.");
|
||||
}
|
||||
}
|
||||
file = f.openNextFile();
|
||||
}
|
||||
f.close();
|
||||
//Remove the dir
|
||||
if (SD_MMC.rmdir(val)) {
|
||||
Serial.printf("Dir %s removed\n", val);
|
||||
} else {
|
||||
Serial.println("Remove dir failed");
|
||||
}
|
||||
|
||||
} else {
|
||||
//Remove the file
|
||||
if (SD_MMC.remove(val)) {
|
||||
Serial.printf("File %s deleted\n", val);
|
||||
} else {
|
||||
Serial.println("Delete failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sdcard:: testwriet()
|
||||
{
|
||||
File file;
|
||||
file = SD_MMC.open("/gps/try.txt", "wb");
|
||||
file.println("hello world");
|
||||
file.flush();
|
||||
file.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void sdcard::WriteStringToFile(String name,String Str)
|
||||
{
|
||||
File file;
|
||||
|
||||
file = SD_MMC.open(name, "w+");
|
||||
file.println(Str);
|
||||
file.flush();
|
||||
file.close();
|
||||
}
|
||||
void sdcard::WriteStringToFile(String name,char *data,size_t lenth)
|
||||
{
|
||||
File file;
|
||||
|
||||
file = SD_MMC.open(name, "wb");
|
||||
file.write((const byte *)data,lenth);
|
||||
file.flush();
|
||||
file.close();
|
||||
}
|
||||
bool sdcard::Mkdir(String path)
|
||||
{
|
||||
return SD_MMC.mkdir(path);
|
||||
}
|
||||
|
||||
namespace sdcard
|
||||
{
|
||||
void openFileformWirte(String Path)
|
||||
{
|
||||
if (Comenfile.available())
|
||||
{
|
||||
Comenfile.close();
|
||||
/* code */
|
||||
}
|
||||
Comenfile = SD_MMC.open(Path, "w+");
|
||||
|
||||
}
|
||||
|
||||
void WritetoFileCommen(String Str)
|
||||
{
|
||||
if (Comenfile.available())
|
||||
{
|
||||
Comenfile.print(Str);
|
||||
Comenfile.flush();
|
||||
/* code */
|
||||
}
|
||||
}
|
||||
|
||||
void WritetoFileCommen(char *data,size_t lenth)
|
||||
{
|
||||
if (Comenfile.available())
|
||||
{
|
||||
Comenfile.write((const byte *)data,lenth);
|
||||
Comenfile.flush();
|
||||
/* code */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void closeCommenFile()
|
||||
{
|
||||
if (Comenfile.available())
|
||||
{
|
||||
Comenfile.close();
|
||||
/* code */
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
28
src/SDmanger.h
Normal file
28
src/SDmanger.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef SDMANGER_H
|
||||
#define SDMANGER_H
|
||||
#include "driver/sdmmc_host.h"
|
||||
#include "driver/sdmmc_defs.h"
|
||||
#include "sdmmc_cmd.h"
|
||||
#include "esp_vfs_fat.h"
|
||||
#include "FS.h"
|
||||
#include <SD_MMC.h>
|
||||
#include "Vector.h"
|
||||
namespace sdcard{
|
||||
int init_sdcard();
|
||||
|
||||
void mylistDir( const char * dirname, uint8_t levels);
|
||||
bool ListDir(const char * dirname,Vector <String> &stringlist);
|
||||
void delete_old_stuff();
|
||||
void deleteFolderOrFile(const char * val) ;
|
||||
void testwriet();
|
||||
void WriteStringToFile(String name,String Str);
|
||||
void WriteStringToFile(String name,char *data,size_t lenth);
|
||||
bool Mkdir(String path);
|
||||
void openFileformWirte(String Path);
|
||||
void WritetoFileCommen(String Str);
|
||||
void WritetoFileCommen(char *data,size_t lenth);
|
||||
void closeCommenFile();
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
281
src/SensorOptoSky.cpp
Normal file
281
src/SensorOptoSky.cpp
Normal file
@ -0,0 +1,281 @@
|
||||
//
|
||||
// Created by xin on 2022/4/24.
|
||||
//
|
||||
|
||||
#include "wifidebug.h"
|
||||
|
||||
|
||||
#include "SensorOptoSky.h"
|
||||
bool SensorOptoSky::initSensor(int id )
|
||||
{
|
||||
IS1Sensor.SetPortName(id);
|
||||
SensorInfo=GetSensorInfo();
|
||||
pinMode(5,OUTPUT);
|
||||
pinMode(6,OUTPUT);
|
||||
// Serial.println("i am here12312312312312312");
|
||||
return true;
|
||||
}
|
||||
|
||||
STRSensorInfo SensorOptoSky::GetSensorInfo() {
|
||||
STRSensorInfo setem;
|
||||
|
||||
if (!IS1Sensor.isSensorInit())
|
||||
{
|
||||
Serial.println("sensor is 123123");
|
||||
return setem;
|
||||
}
|
||||
int lenthretrunl;
|
||||
char *result;
|
||||
|
||||
IS1Sensor.SendComment(GET_PN_NUMBER);
|
||||
IS1Sensor.GetReturn(GET_PN_NUMBER, lenthretrunl,1000);
|
||||
result=new char[lenthretrunl+1]();
|
||||
memcpy(result,IS1Sensor.result,lenthretrunl);
|
||||
result[lenthretrunl]='\0';
|
||||
|
||||
String str(result);
|
||||
Serial.println(str);
|
||||
delete[] result;
|
||||
str.remove(str.indexOf("00")+1,str.length()-(str.indexOf("00")+1));
|
||||
setem.SensorName=str;
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
IS1Sensor.SendComment(GET_SN_NUMBER);
|
||||
IS1Sensor.GetReturn(GET_SN_NUMBER, lenthretrunl,1000);
|
||||
result=new char[lenthretrunl+1]();
|
||||
memcpy(result,IS1Sensor.result,lenthretrunl);
|
||||
result[lenthretrunl]='\0';
|
||||
String SNNUMBER(result);
|
||||
Serial.println(SNNUMBER);
|
||||
delete[] result;//
|
||||
SNNUMBER.remove(SNNUMBER.indexOf('X'),SNNUMBER.length()-SNNUMBER.indexOf('X'));
|
||||
setem.serialnumber=SNNUMBER;
|
||||
/*
|
||||
Serial.write("IS1Sensor.result+10,lenthretrunl");
|
||||
Serial.write(IS1Sensor.result+3,lenthretrunl-3);
|
||||
Serial.println("SNNUMBER");
|
||||
Serial.println(SNNUMBER);
|
||||
|
||||
*/
|
||||
////////////////////////
|
||||
|
||||
|
||||
u_char *shutter=new u_char[2]();
|
||||
int msc=10;
|
||||
shutter[0] = (int)msc / 256;
|
||||
shutter[1] = (int)msc % 256;
|
||||
IS1Sensor.SendComment(SYNCHRONIZATION_GET_DATA,shutter,2);
|
||||
IS1Sensor.GetReturn(SYNCHRONIZATION_GET_DATA, lenthretrunl,10);
|
||||
setem.BandNum = (lenthretrunl-1)/2;
|
||||
Serial.println("band lenth:" );
|
||||
Serial.println( setem.BandNum );
|
||||
DATABUFF=new unsigned short[setem.BandNum] ;
|
||||
DownData=new unsigned short[setem.BandNum] ;
|
||||
UpData=new unsigned short[setem.BandNum] ;
|
||||
////////////////////////////////////////////////////////
|
||||
shutter[0] = 0x00;
|
||||
shutter[1] = 0x01;
|
||||
IS1Sensor.SendComment(GET_WAVELENGTH_CALIBRATION_COFF,shutter,2);
|
||||
IS1Sensor.GetReturn(GET_WAVELENGTH_CALIBRATION_COFF, lenthretrunl);
|
||||
float a[4];
|
||||
memcpy(a, IS1Sensor.result + 16, 4 * 4);
|
||||
|
||||
int bandsss= setem.BandNum;
|
||||
setem.wavelenthlist=new float[setem.BandNum]();
|
||||
Serial.print("a0:");
|
||||
Serial.print(a[0]);
|
||||
Serial.print(" a1:");
|
||||
Serial.print(a[1]);
|
||||
Serial.print(" a2:");
|
||||
Serial.print(a[2]);
|
||||
Serial.print(" a3:");
|
||||
Serial.println(a[3]);
|
||||
setem.a1=a[0];
|
||||
setem.a2=a[1];
|
||||
setem.a3=a[2];
|
||||
setem.a4=a[3];
|
||||
for ( int i = 1; i <=bandsss ; i++)
|
||||
{
|
||||
setem.wavelenthlist[i-1] = a[0] * i*i*i + a[1] * i*i + a[2] * i + a[3];
|
||||
|
||||
}
|
||||
///////////////////////////////////////////////////
|
||||
shutter[0] = 0x00;
|
||||
shutter[1] = 0x01;
|
||||
|
||||
IS1Sensor.SendComment(SET_AVERAGE_NUMBER, shutter,2);
|
||||
IS1Sensor.GetReturn(SET_AVERAGE_NUMBER, lenthretrunl);
|
||||
setem.maxValue=65535;
|
||||
delete[] shutter;
|
||||
|
||||
return setem;
|
||||
/* 非线性校正
|
||||
IS1Sensor.SendComment(0x53, shutter,2);
|
||||
IS1Sensor. GetReturn(0x53, lenthretrunl);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void SensorOptoSky::SetShutter(int id) {
|
||||
switch (id) {
|
||||
case 0:
|
||||
{
|
||||
digitalWrite(5,LOW);
|
||||
digitalWrite(6,LOW);
|
||||
delay(200);
|
||||
break;
|
||||
}
|
||||
case 1:{
|
||||
digitalWrite(6,HIGH);
|
||||
digitalWrite(5,LOW);
|
||||
delay(200);
|
||||
break;
|
||||
}
|
||||
case 2:{
|
||||
digitalWrite(5,HIGH);
|
||||
digitalWrite(6,LOW);
|
||||
delay(200);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SensorOptoSky::GetOneDate(int msc) {
|
||||
u_char *shutter=new u_char[2]();
|
||||
shutter[0] = (int)msc / 256;
|
||||
shutter[1] = (int)msc % 256;
|
||||
int lenthretrunl;
|
||||
IS1Sensor.SendComment(SYNCHRONIZATION_GET_DATA,shutter,2);
|
||||
IS1Sensor.GetReturn(SYNCHRONIZATION_GET_DATA, lenthretrunl,msc);
|
||||
memcpy(DATABUFF, IS1Sensor.result + 1, SensorInfo.BandNum * 2);
|
||||
shortLittletoBiG(DATABUFF, SensorInfo.BandNum);
|
||||
}
|
||||
|
||||
void SensorOptoSky::shortLittletoBiG(unsigned short *data, int lenth) {
|
||||
char *chardata=(char *)data;
|
||||
char temp;
|
||||
for (int i = 0; i <lenth ; ++i) {
|
||||
temp=chardata[2*i+1];
|
||||
chardata[2*i+1]=chardata[2*i];
|
||||
chardata[2*i]=temp;
|
||||
}
|
||||
}
|
||||
|
||||
int SensorOptoSky::OptSnenser(int persent) {
|
||||
long maxtime = 20000;
|
||||
int maxvalue=SensorInfo.maxValue*1.0*persent / 100;
|
||||
int maxvaluenow = 0;
|
||||
float shutternow = 10;
|
||||
GetOneDate(shutternow);
|
||||
maxvaluenow= Getmaxvalue(DATABUFF, SensorInfo.BandNum);
|
||||
Serial.print("now Shutter is :");
|
||||
Serial.print(shutternow);
|
||||
Serial.print(" maxvalue is :");
|
||||
Serial.println(maxvaluenow);
|
||||
int numberoftry = 0;
|
||||
while (maxvaluenow<maxvalue*0.95 || maxvaluenow>maxvalue) {
|
||||
if (maxvaluenow > maxvalue)
|
||||
{
|
||||
shutternow = shutternow *0.7;
|
||||
}
|
||||
else
|
||||
{
|
||||
shutternow = maxvalue * 0.98 / (maxvaluenow * 1.0)*shutternow + 1;
|
||||
}
|
||||
if (shutternow > maxtime)
|
||||
{
|
||||
shutternow = maxtime;
|
||||
break;
|
||||
}
|
||||
GetOneDate(shutternow);
|
||||
maxvaluenow= Getmaxvalue(DATABUFF, SensorInfo.BandNum);
|
||||
Serial.print("now Shutter is :");
|
||||
Serial.print(shutternow);
|
||||
Serial.print(" maxvalue is :");
|
||||
Serial.println(maxvaluenow);
|
||||
numberoftry++;
|
||||
if (numberoftry > 200)
|
||||
{
|
||||
|
||||
return maxtime;
|
||||
|
||||
}
|
||||
if (shutternow == maxtime)
|
||||
{
|
||||
|
||||
return maxtime;
|
||||
}
|
||||
}
|
||||
Serial.print("zi dong value:");
|
||||
Serial.println(shutternow);
|
||||
if (shutternow<0)
|
||||
{
|
||||
shutternow=maxtime;
|
||||
/* code */
|
||||
}
|
||||
|
||||
return shutternow;
|
||||
}
|
||||
|
||||
int SensorOptoSky::Getmaxvalue(unsigned short *data, int lenth) {
|
||||
int ret=-1;
|
||||
for (int i = 0; i < lenth; ++i) {
|
||||
if (data[i]>ret){
|
||||
ret=data[i];
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SensorOptoSky::TakeOneJob() {
|
||||
SetShutter(1);
|
||||
int shutter=OptSnenser(90);
|
||||
shutterup=shutter;
|
||||
GetOneDate(shutter);
|
||||
memcpy(UpData,DATABUFF,SensorInfo.BandNum*2);
|
||||
SetShutter(0);
|
||||
GetOneDate(shutter);
|
||||
for (int i = 0; i < SensorInfo.BandNum; ++i) {
|
||||
UpData[i]=UpData[i]-DATABUFF[i];
|
||||
}
|
||||
shutterup=shutter;
|
||||
Serial.println("Finish Up ------Green");
|
||||
bool dingbing=false;
|
||||
#ifdef DINBIAO
|
||||
|
||||
String strout="1 shutteruo is "+String(shutterup)+" Finish Up ------Green ";
|
||||
printbytcpserver(strout);
|
||||
PrintFunc(strout );
|
||||
digitalWrite(21, LOW);
|
||||
printbytcpserver("please change the fiber in 1 min");
|
||||
delay(90000);
|
||||
SensorInfo.SensorName=SensorInfo.SensorName+"cali";
|
||||
Serial.println("begindown");
|
||||
digitalWrite(21, HIGH);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
SetShutter(2);
|
||||
shutter=OptSnenser(90);
|
||||
shutterdown=shutter;
|
||||
GetOneDate(shutter);
|
||||
memcpy(DownData,DATABUFF,SensorInfo.BandNum*2);
|
||||
SetShutter(0);
|
||||
GetOneDate(shutter);
|
||||
for (int i = 0; i < SensorInfo.BandNum; ++i) {
|
||||
DownData[i]=DownData[i]-DATABUFF[i];
|
||||
}
|
||||
shutterdown=shutter;
|
||||
Serial.println("Down Finish ------Blue");
|
||||
#ifdef DINBIAO
|
||||
String strout1="2 shutterdown is "+String(shutterdown)+" Down Finish ------Blue";
|
||||
PrintFunc(strout1 );
|
||||
printbytcpserver(strout1);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
32
src/SensorOptoSky.h
Normal file
32
src/SensorOptoSky.h
Normal file
@ -0,0 +1,32 @@
|
||||
//
|
||||
// Created by xin on 2022/4/24.
|
||||
//
|
||||
|
||||
#ifndef ESP32MAINBOARD_SENSOROPTOSKY_H
|
||||
#define ESP32MAINBOARD_SENSOROPTOSKY_H
|
||||
;
|
||||
#include "optoskybase.h"
|
||||
typedef void (*PRINTFUNC)(String );
|
||||
class SensorOptoSky {
|
||||
public:
|
||||
STRSensorInfo SensorInfo;
|
||||
OptoSky IS1Sensor;
|
||||
bool initSensor(int id = 2);
|
||||
STRSensorInfo GetSensorInfo();
|
||||
void SetShutter(int id);// 0 dark 1 green 2 blue
|
||||
void GetOneDate(int msc);
|
||||
unsigned short *DATABUFF;
|
||||
int shutterup,shutterdown;
|
||||
unsigned short *DownData;
|
||||
unsigned short *UpData;
|
||||
void shortLittletoBiG( unsigned short *data,int lenth);
|
||||
int OptSnenser(int percent);
|
||||
int Getmaxvalue(unsigned short *data,int lenth);
|
||||
void TakeOneJob();
|
||||
PRINTFUNC PrintFunc;
|
||||
//int shutterup,shutterdown;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //ESP32MAINBOARD_SENSOROPTOSKY_H
|
||||
206
src/TCPserver.cpp
Normal file
206
src/TCPserver.cpp
Normal file
@ -0,0 +1,206 @@
|
||||
#include "TCPserver.h"
|
||||
bool fenge(String &zifuchuan, String &outstring, String fengefu)
|
||||
{
|
||||
int weizhi = 0; //找查的位置
|
||||
|
||||
if (zifuchuan == "")
|
||||
{
|
||||
// Serial.print("commanesdafasdf");
|
||||
return false;
|
||||
|
||||
/* code */
|
||||
}
|
||||
|
||||
weizhi = zifuchuan.indexOf(fengefu); //找到位置
|
||||
if (weizhi != -1) //如果位置不为空
|
||||
{
|
||||
// Serial.println(zifuchuan);
|
||||
outstring = zifuchuan.substring(0, weizhi); //打印取第一个字符
|
||||
zifuchuan = zifuchuan.substring(weizhi + fengefu.length(), zifuchuan.length());
|
||||
return true;
|
||||
//分隔后只取后面一段内容 以方便后面找查
|
||||
}
|
||||
else
|
||||
{
|
||||
// Serial.print(zifuchuan);
|
||||
outstring = zifuchuan;
|
||||
zifuchuan = "";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
TCPserver::TCPserver(int port)
|
||||
{
|
||||
server = new WiFiServer(port);
|
||||
myserial = nullptr;
|
||||
isPortOutInit = false;
|
||||
|
||||
}
|
||||
#if ARDUINO_USB_CDC_ON_BOOT && !ARDUINO_USB_MODE
|
||||
TCPserver::TCPserver(USBCDC *serial,int port)
|
||||
{
|
||||
server = new WiFiServer(port);
|
||||
myserial = serial;
|
||||
isPortOutInit = true;
|
||||
|
||||
}
|
||||
#elif ARDUINO_USB_CDC_ON_BOOT && ARDUINO_USB_MODE
|
||||
TCPserver::TCPserver(HWCDC *serial,int port)
|
||||
{
|
||||
server = new WiFiServer(port);
|
||||
myserial = serial;
|
||||
isPortOutInit = true;
|
||||
|
||||
}
|
||||
#else
|
||||
TCPserver::TCPserver(HardwareSerial *serial, int port /* args */)
|
||||
{
|
||||
server = new WiFiServer(port);
|
||||
myserial = serial;
|
||||
isPortOutInit = true;
|
||||
|
||||
}
|
||||
#endif
|
||||
void TCPserver::initme()
|
||||
{
|
||||
server->begin();
|
||||
//关闭小包合并包功能,不会延时发送数据
|
||||
server->setNoDelay(true);
|
||||
}
|
||||
void TCPserver::loop()
|
||||
{
|
||||
uint8_t i;
|
||||
//检测是否有新的client请求进来
|
||||
// myserial->print("asdffsd");
|
||||
if (server->hasClient())
|
||||
{
|
||||
for (i = 0; i < MAX_SRV_CLIENTS; i++)
|
||||
{
|
||||
//释放旧无效或者断开的client
|
||||
if (!serverClients[i] || !serverClients[i].connected())
|
||||
{
|
||||
if (serverClients[i])
|
||||
{
|
||||
serverClients[i].stop();
|
||||
}
|
||||
//分配最新的client
|
||||
serverClients[i] = server->available();
|
||||
if (isPortOutInit)
|
||||
{
|
||||
myserial->print("New client: ");
|
||||
myserial->print(i);
|
||||
/* code */
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
//当达到最大连接数 无法释放无效的client,需要拒绝连接
|
||||
if (i == MAX_SRV_CLIENTS)
|
||||
{
|
||||
WiFiClient serverClient = server->available();
|
||||
serverClient.stop();
|
||||
if (isPortOutInit)
|
||||
{
|
||||
myserial->print("Connection rejected ");
|
||||
}
|
||||
}
|
||||
}
|
||||
//检测client发过来的数据
|
||||
for (i = 0; i < MAX_SRV_CLIENTS; i++)
|
||||
{
|
||||
if (serverClients[i] && serverClients[i].connected())
|
||||
{
|
||||
if (serverClients[i].available())
|
||||
{
|
||||
// get data from the telnet client and push it to the UART
|
||||
String str = "";
|
||||
while (serverClients[i].available())
|
||||
{
|
||||
//发送到串口调试器
|
||||
if (isPortOutInit)
|
||||
{
|
||||
str = str + String((char)serverClients[i].read());
|
||||
// myserial->write(serverClients[i].read());
|
||||
/* code */
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isPortOutInit)
|
||||
{
|
||||
|
||||
if (myserial->available())
|
||||
{
|
||||
//把串口调试器发过来的数据 发送给client
|
||||
size_t len = myserial->available();
|
||||
uint8_t sbuf[len];
|
||||
myserial->readBytes(sbuf, len);
|
||||
// push UART data to all connected telnet clients
|
||||
for (i = 0; i < MAX_SRV_CLIENTS; i++)
|
||||
{
|
||||
if (serverClients[i] && serverClients[i].connected())
|
||||
{
|
||||
serverClients[i].write(sbuf, len);
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void TCPserver::SendDataToClinet(String str, int clinetid)
|
||||
{
|
||||
|
||||
// myserial->print("Connection rejected ");
|
||||
if (clinetid == -1)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < MAX_SRV_CLIENTS; i++)
|
||||
{
|
||||
if (serverClients[i] && serverClients[i].connected())
|
||||
{
|
||||
serverClients[i].println(str);
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
/* code */
|
||||
}
|
||||
else
|
||||
{
|
||||
if (serverClients[clinetid] && serverClients[clinetid].connected())
|
||||
{
|
||||
serverClients[clinetid].println(str);
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
void TCPserver::SendDataToClinet(char *str, int clinetid)
|
||||
{
|
||||
// push UART data to all connected telnet clients
|
||||
myserial->print("Connection rejected ");
|
||||
if (clinetid == -1)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < MAX_SRV_CLIENTS; i++)
|
||||
{
|
||||
if (serverClients[i] && serverClients[i].connected())
|
||||
{
|
||||
serverClients[i].write(str);
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
/* code */
|
||||
}
|
||||
else
|
||||
{
|
||||
if (serverClients[clinetid] && serverClients[clinetid].connected())
|
||||
{
|
||||
serverClients[clinetid].write(str);
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
TCPserver::~TCPserver()
|
||||
{
|
||||
delete server;
|
||||
}
|
||||
54
src/TCPserver.h
Normal file
54
src/TCPserver.h
Normal file
@ -0,0 +1,54 @@
|
||||
#ifndef TCPSERVER_H
|
||||
#define TCPSERVER_H
|
||||
|
||||
#include<HardwareSerial.h>
|
||||
#ifdef ESP8266
|
||||
#include <ESP8266WiFi.h>
|
||||
#else
|
||||
#include<WiFi.h>
|
||||
#endif
|
||||
|
||||
#define MAX_SRV_CLIENTS 2
|
||||
class TCPserver
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
//创建server 端口号是23
|
||||
WiFiServer *server;
|
||||
//管理clients
|
||||
WiFiClient serverClients[MAX_SRV_CLIENTS];
|
||||
|
||||
bool isPortOutInit;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
#if ARDUINO_USB_CDC_ON_BOOT && !ARDUINO_USB_MODE //Serial used for USB CDC
|
||||
USBCDC *myserial;
|
||||
TCPserver(USBCDC *serial,int port);
|
||||
#elif ARDUINO_USB_CDC_ON_BOOT && ARDUINO_USB_MODE
|
||||
HWCDC *myserial;
|
||||
TCPserver(HWCDC *serial,int port);
|
||||
#else
|
||||
HardwareSerial *myserial;
|
||||
TCPserver(HardwareSerial *serial,int port);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
TCPserver(int port);
|
||||
void initme();
|
||||
~TCPserver();
|
||||
void SendDataToClinet(String str,int clinetid=-1);
|
||||
void SendDataToClinet(char *str,int clinetid=-1);
|
||||
void loop();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
46
src/log.cpp
Normal file
46
src/log.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include "log.h"
|
||||
/*
|
||||
|
||||
w+以纯文本方式读写,而wb+是以二进制方式进行读写。
|
||||
|
||||
mode说明:
|
||||
|
||||
w 打开只写文件,若文件存在则文件长度清为0,即该文件内容会消失。若文件不存在则建立该文件。
|
||||
|
||||
w+ 打开可读写文件,若文件存在则文件长度清为零,即该文件内容会消失。若文件不存在则建立该文件。
|
||||
|
||||
wb 只写方式打开或新建一个二进制文件,只允许写数据。
|
||||
|
||||
wb+ 读写方式打开或建立一个二进制文件,允许读和写。
|
||||
|
||||
r 打开只读文件,该文件必须存在,否则报错。
|
||||
|
||||
r+ 打开可读写的文件,该文件必须存在,否则报错。
|
||||
|
||||
rb+ 读写方式打开一个二进制文件,只允许读写数据。
|
||||
|
||||
a 以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留。(EOF符保留)
|
||||
|
||||
a+ 以附加方式打开可读写的文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾后,即文件原先的内容会被保留。 (原来的EOF符不保留)
|
||||
|
||||
ab+ 读写打开一个二进制文件,允许读或在文件末追加数据。
|
||||
|
||||
加入b 字符用来告诉函数库打开的文件为二进制文件,而非纯文字文件。
|
||||
*/
|
||||
|
||||
void write_log(String path,unsigned char level,String write_data)
|
||||
{
|
||||
#ifdef ceshi
|
||||
Serial.println(write_data);
|
||||
#endif
|
||||
|
||||
if(level > 10) {
|
||||
//保存本地,和同时上传云端,小于10只保存本地
|
||||
}
|
||||
|
||||
File file;
|
||||
file = SD_MMC.open(path,"a+");
|
||||
file.println(write_data);
|
||||
file.flush();
|
||||
file.close();
|
||||
}
|
||||
12
src/log.h
Normal file
12
src/log.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef _LOG_H_
|
||||
#define _LOG_H_
|
||||
|
||||
|
||||
#define ceshi 1
|
||||
#include "SDmanger.h"
|
||||
void write_log(String path,unsigned char level,String write_data);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
759
src/main.cpp
Normal file
759
src/main.cpp
Normal file
@ -0,0 +1,759 @@
|
||||
#include"Define.h"
|
||||
#include <GSMMannager.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <ArduinoHttpClient.h>
|
||||
#include<driver/periph_ctrl.h>
|
||||
#include "SensorOptoSky.h"
|
||||
#include <SoftwareSerial.h>
|
||||
#include <Ticker.h>
|
||||
#include <updatebyme.h>
|
||||
//#include "MyWebServer.h"
|
||||
#include "SDmanger.h"
|
||||
//#include "HttpsOTAUpdate.h"
|
||||
#include "slave.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <wifidebug.h>
|
||||
|
||||
#define LOGGING
|
||||
//myPort将原来ESP8266对内通讯改为,485对内的通讯
|
||||
// #define MYPORT_TX 45
|
||||
// #define MYPORT_RX 46
|
||||
int hassend = 0;
|
||||
GSMMannger *gsmmanger;
|
||||
UpDateClassByme *ProgrameUper;
|
||||
HttpClient *http;
|
||||
bool ishttpbusy = false;
|
||||
SensorOptoSky IS1Sensor;
|
||||
// SoftwareSerial myPort(MYPORT_RX, MYPORT_TX, false);
|
||||
// HardwareSerial myPort(1);
|
||||
// swSer(14, 12, false, 256);
|
||||
// u_char a[]={0x01,0x04,0x00,0x00,0x00,0x06,0x70,0x08};
|
||||
u_char ret[17];
|
||||
u_char windret[17];
|
||||
Ticker ticker;
|
||||
slave myslave;
|
||||
|
||||
String getnetData()
|
||||
{
|
||||
int err = http->get("/weather/php/Date.php");
|
||||
if (err != 0)
|
||||
{
|
||||
SerialMon.println(F("Date failed to connect"));
|
||||
delay(10000);
|
||||
return "";
|
||||
}
|
||||
int status = http->responseStatusCode();
|
||||
if (!status)
|
||||
{
|
||||
delay(10000);
|
||||
return "";
|
||||
}
|
||||
|
||||
// SerialMon.println(F("Response Headers:"));
|
||||
while (http->headerAvailable())
|
||||
{
|
||||
String headerName = http->readHeaderName();
|
||||
String headerValue = http->readHeaderValue();
|
||||
// SerialMon.println("Date: " + headerName + " : " + headerValue);
|
||||
}
|
||||
if (http->isResponseChunked())
|
||||
{
|
||||
// SerialMon.println(F("Date The response is chunked"));
|
||||
}
|
||||
|
||||
String body = http->responseBody();
|
||||
http->stop();
|
||||
return body;
|
||||
}
|
||||
bool UpdateData(String path, char *str, size_t lenth, String Contenttype = "")
|
||||
{
|
||||
|
||||
http->beginRequest();
|
||||
http->post(path);
|
||||
if (Contenttype != "")
|
||||
{
|
||||
http->sendHeader(HTTP_HEADER_CONTENT_TYPE, Contenttype);
|
||||
|
||||
/* code */
|
||||
}
|
||||
|
||||
http->sendHeader(HTTP_HEADER_CONTENT_LENGTH, lenth);
|
||||
http->endRequest();
|
||||
int err = http->write((const byte *)str, lenth);
|
||||
delay(1000);
|
||||
Serial.print("send date size");
|
||||
Serial.println(err);
|
||||
|
||||
/*
|
||||
for (size_t i = 0; i < lenth; i++)
|
||||
{
|
||||
Serial.print("0x");
|
||||
Serial.print(str[i],HEX);
|
||||
Serial.print(" ");
|
||||
if (i%20==0)
|
||||
{
|
||||
Serial.println(" ");
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
// http->write((const byte*)IS1Sensor.UpData, IS1Sensor.SensorInfo.BandNum*2);
|
||||
// http->stop();
|
||||
Serial.println("hear1");
|
||||
if (err == 0)
|
||||
{
|
||||
|
||||
http->stop();
|
||||
return false;
|
||||
}
|
||||
int status = http->responseStatusCode();
|
||||
Serial.println("hear3");
|
||||
if (!status)
|
||||
{
|
||||
http->stop();
|
||||
return false;
|
||||
}
|
||||
|
||||
int length = http->contentLength();
|
||||
Serial.println("hear4");
|
||||
if (length == 0)
|
||||
{
|
||||
http->stop();
|
||||
return false;
|
||||
}
|
||||
|
||||
String body = http->responseBody();
|
||||
Serial.println("body:"+body);
|
||||
if (body != "ok")
|
||||
{
|
||||
http->stop();
|
||||
return false;
|
||||
}
|
||||
|
||||
http->stop();
|
||||
return true;
|
||||
}
|
||||
void ReuploadData(String path, String webpath, String content = "")
|
||||
{
|
||||
vTaskDelay(1);
|
||||
Vector<String> files;
|
||||
String vec[20]; //每次处理20个
|
||||
files.setStorage(vec);
|
||||
while (!sdcard::ListDir(path.c_str(), files))
|
||||
{
|
||||
if (files.size() != 0)
|
||||
{
|
||||
Serial.println("find " + String(files.size()) + "file");
|
||||
for (size_t i = 0; i < files.size(); i++)
|
||||
{
|
||||
File nowfile = SD_MMC.open(files.at(i).c_str(), "rb");
|
||||
size_t size = nowfile.size();
|
||||
char *arr = new char[size];
|
||||
nowfile.readBytes(arr, size);
|
||||
bool flagsucc = UpdateData(webpath, arr, size, content);
|
||||
if (!flagsucc)
|
||||
{
|
||||
return;
|
||||
/* code */
|
||||
}
|
||||
delete[] arr;
|
||||
sdcard::deleteFolderOrFile(files.at(i).c_str());
|
||||
vTaskDelay(1);
|
||||
/* code */
|
||||
}
|
||||
}
|
||||
vTaskDelay(1);
|
||||
}
|
||||
if (files.size() != 0)
|
||||
{
|
||||
Serial.println("find " + String(files.size()) + "file not enough 20");
|
||||
for (size_t i = 0; i < files.size(); i++)
|
||||
{
|
||||
vTaskDelay(1);
|
||||
File nowfile = SD_MMC.open(files.at(i).c_str(), "rb");
|
||||
size_t size = nowfile.size();
|
||||
char *arr = new char[size];
|
||||
nowfile.readBytes(arr, size);
|
||||
Serial.println("run here now");
|
||||
bool flagsucc = UpdateData(webpath, arr, size, content);
|
||||
if (!flagsucc)
|
||||
{
|
||||
return;
|
||||
/* code */
|
||||
}
|
||||
|
||||
delete[] arr;
|
||||
sdcard::deleteFolderOrFile(files.at(i).c_str());
|
||||
/* code */
|
||||
}
|
||||
}
|
||||
vTaskDelay(1);
|
||||
}
|
||||
String fenge(String str, String fen, int index)
|
||||
{
|
||||
int weizhi;
|
||||
String temps[str.length()];
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
weizhi = str.indexOf(fen);
|
||||
if (weizhi != -1)
|
||||
{
|
||||
temps[i] = str.substring(0, weizhi);
|
||||
str = str.substring(weizhi + fen.length(), str.length());
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (str.length() > 0)
|
||||
temps[i] = str;
|
||||
}
|
||||
} while (weizhi >= 0);
|
||||
|
||||
if (index > i)
|
||||
return "-1";
|
||||
return temps[index];
|
||||
}
|
||||
void Reuploaddata(void *) //重新上传数据
|
||||
{
|
||||
ReuploadData("/down", "/weather/php/SpectralDataUp.php");
|
||||
ReuploadData("/up", "/weather/php/SpectralDataUp.php");
|
||||
ReuploadData("/other", "/weather/php/WindsensorUp.php", "application/json");
|
||||
}
|
||||
void Reuploaddata() //重新上传数据
|
||||
{
|
||||
ReuploadData("/down", "/weather/php/SpectralDataUp.php");
|
||||
ReuploadData("/up", "/weather/php/SpectralDataUp.php");
|
||||
ReuploadData("/other", "/weather/php/WindsensorUp.php", "application/json");
|
||||
|
||||
}
|
||||
|
||||
String Datenow="";
|
||||
void printbytcp(String str)
|
||||
{
|
||||
//tcpserver.SendDataToClinet(str);
|
||||
Serial.println(str);
|
||||
str=Datenow+"#######"+str;
|
||||
int lennn=str.length();
|
||||
char *temp = new char[lennn];
|
||||
memcpy(temp, str.c_str(), str.length());
|
||||
bool flagsucc = UpdateData("/weather/php/log.php", temp, lennn);
|
||||
vTaskDelay(3000);
|
||||
delete[] temp;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void esp8266_readmeichaung()
|
||||
{
|
||||
//读取美创模块
|
||||
// while (myPort.read() != -1)
|
||||
// ;
|
||||
// delay(1000); //等待1s 防止下位机反应不过来
|
||||
// myPort.println("MLX#");
|
||||
// delay(10);
|
||||
// for (int j = 0; j < 8; ++j)
|
||||
// {
|
||||
// ret[j] = myPort.read();
|
||||
// }
|
||||
// double temprature;
|
||||
// memcpy(&temprature, ret, 8);
|
||||
// Serial.println("wendu");
|
||||
// Serial.println(temprature);
|
||||
// Serial.println("hello word");
|
||||
|
||||
///////////////now///////////////////////////
|
||||
double temprature = myslave.getMLX();
|
||||
Serial.println("wendu");
|
||||
Serial.println(temprature);
|
||||
Serial.println("hello word");
|
||||
|
||||
|
||||
|
||||
/////////////////////////////初始化windsensor并测评1<E8AF84>71ᅣ1<EFBF84>77/////////////////////////////////////////////////////////////
|
||||
// while (myPort.read() != -1)
|
||||
// ;
|
||||
// sleep(1);
|
||||
// myPort.println("WindSensor#");
|
||||
// delay(210);
|
||||
// for (int j = 0; j < 17; ++j)
|
||||
// {
|
||||
// windret[j] = myPort.read();
|
||||
// }
|
||||
// float VV = (windret[3] * 256 + windret[4]) * 1.0 / 100;
|
||||
// float DD = (windret[5] * 256 + windret[6]) * 1.0 / 10;
|
||||
// float TT = (windret[7] * 256 + windret[8]) * 1.0 / 100;
|
||||
// float HH = (windret[9] * 256 + windret[10]) * 1.0 / 100;
|
||||
// long PP = (windret[13] * 256 + windret[14]) * 256 * 256 + (windret[11] * 256 + windret[12]);
|
||||
// Serial.println("VV:" + String(VV) + "DD:" + String(DD) + "TT:" + String(TT) + "HH:" + String(HH) + "PP:" + String(PP));
|
||||
|
||||
|
||||
////////////////////////////////now////////////////////////////
|
||||
myslave.getWehter();
|
||||
memcpy(windret,myslave.ret,17);
|
||||
float VV = (windret[3] * 256 + windret[4]) * 1.0 / 100;
|
||||
float DD = (windret[5] * 256 + windret[6]) * 1.0 / 10;
|
||||
float TT = (windret[7] * 256 + windret[8]) * 1.0 / 100;
|
||||
float HH = (windret[9] * 256 + windret[10]) * 1.0 / 100;
|
||||
long PP = (windret[13] * 256 + windret[14]) * 256 * 256 + (windret[11] * 256 + windret[12]);
|
||||
Serial.println("VV:" + String(VV) + "DD:" + String(DD) + "TT:" + String(TT) + "HH:" + String(HH) + "PP:" + String(PP));
|
||||
}
|
||||
|
||||
|
||||
String get_GPS(void)
|
||||
{
|
||||
Serial.println("check GPS...");
|
||||
gsmmanger->modem->sendAT(GF("+CGNSPWR?"));
|
||||
gsmmanger->modem->waitResponse("OK");
|
||||
|
||||
Serial.println("Open GPS...");
|
||||
gsmmanger->modem->sendAT(GF("+CGNSPWR=1"));
|
||||
gsmmanger->modem->waitResponse("OK");
|
||||
|
||||
gsmmanger->modem->sendAT(GF("+CGNSAID=31,1,1,1"));
|
||||
gsmmanger->modem->waitResponse("OK");
|
||||
|
||||
Serial.println("get GNSS...");
|
||||
gsmmanger->modem->sendAT(GF("+CGNSINF"));
|
||||
|
||||
String gps;
|
||||
gsmmanger->modem->waitResponse(5000,gps);
|
||||
// Serial.println(gps);
|
||||
|
||||
return gps;
|
||||
}
|
||||
|
||||
|
||||
String log_path;
|
||||
String log_data;
|
||||
void setup()
|
||||
{
|
||||
Serial2.begin(115200);
|
||||
|
||||
Serial.begin(115200);
|
||||
sdcard::init_sdcard();
|
||||
sdcard::testwriet();
|
||||
sdcard::Mkdir("/up");
|
||||
sdcard::Mkdir("/down");
|
||||
sdcard::Mkdir("/other");
|
||||
sdcard::Mkdir("/gps");
|
||||
sdcard::Mkdir("/log");
|
||||
beginWIFI();
|
||||
// sdcard::mylistDir("/",2);
|
||||
{
|
||||
}
|
||||
// pinMode(21, OUTPUT);
|
||||
// digitalWrite(21, HIGH);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// return;
|
||||
//重启esp8266现在不用
|
||||
// pinMode(5, OUTPUT);
|
||||
// digitalWrite(5, LOW);
|
||||
// delay(500);
|
||||
// digitalWrite(5, HIGH);
|
||||
|
||||
|
||||
// pinMode(22,OUTPUT);
|
||||
// digitalWrite(22,HIGH);
|
||||
// pinMode(23,OUTPUT);
|
||||
// digitalWrite(23,HIGH);
|
||||
|
||||
|
||||
//将原来通过esp8266读取美创写成函数esp8266_readmeichaung(),方便调试。
|
||||
|
||||
// myPort.begin(38400, SWSERIAL_8N1, MYPORT_RX, MYPORT_TX, false);
|
||||
myslave.init(46,45);
|
||||
sleep(3);
|
||||
// esp8266_readmeichaung();
|
||||
//原来的SIM800,改为现在的AIR780E4G模块,使用的是串口2。
|
||||
gsmmanger = new GSMMannger(2, 19, 20);
|
||||
|
||||
http = new HttpClient(*gsmmanger->client, "82.156.1.111");
|
||||
|
||||
String Date = getnetData();
|
||||
Serial.println("date is :"+Date);
|
||||
String tem = fenge(Date," ",0);
|
||||
log_path = "/log/"+tem+".txt";
|
||||
log_data = Date+"\r\nSystem starts working.";
|
||||
write_log(log_path,10,"");
|
||||
write_log(log_path,10,log_data);
|
||||
write_log(log_path,10,"AIR780E Init Success.");
|
||||
vTaskDelay(1000);
|
||||
|
||||
|
||||
gsmmanger->modem->sendAT(GF("+CGPIO=1,11,1")); //点灯
|
||||
gsmmanger->modem->waitResponse("OK");
|
||||
String gpsbac = get_GPS();
|
||||
Serial.println(gpsbac);
|
||||
write_log(log_path,10,"GPS Init Success.");
|
||||
vTaskDelay(1000);
|
||||
//////////////////////////////初始化http模块//////////////////////////////////////////////
|
||||
// http = new HttpClient(*gsmmanger->client, "82.156.1.111");
|
||||
ProgrameUper = new UpDateClassByme(http);
|
||||
|
||||
IS1Sensor.initSensor();
|
||||
String StationID = IS1Sensor.SensorInfo.serialnumber;
|
||||
String SensorID = IS1Sensor.SensorInfo.SensorName;
|
||||
|
||||
|
||||
ProgrameUper->initme(Curentvsion);
|
||||
ProgrameUper->StationID=StationID;
|
||||
ProgrameUper->CheckAndUpdate();
|
||||
write_log(log_path,10,"Http Init Success.");
|
||||
// ProgrameUper->DownloadFirmwareForurl("");
|
||||
////////////////////////////上传IS1设备信息//////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////初始化IS1///////////////////////////////////////////////////
|
||||
|
||||
// String Date=getnetData();
|
||||
String Upheader = StationID + "##" + SensorID + "##" + String(IS1Sensor.SensorInfo.BandNum) + "##"
|
||||
+ String(IS1Sensor.SensorInfo.a1,9) + ":" + String(IS1Sensor.SensorInfo.a2,9) + ":" + String(IS1Sensor.SensorInfo.a3,9) + ":" + String(IS1Sensor.SensorInfo.a4,9)+"##"+ProgrameUper->CurrentVersion;
|
||||
http->beginRequest();
|
||||
http->post("/weather/php/SensorInfoUp.php");
|
||||
http->sendHeader(HTTP_HEADER_CONTENT_LENGTH, Upheader.length());
|
||||
http->endRequest();
|
||||
http->write((const byte *)Upheader.c_str(), Upheader.length());
|
||||
http->stop();
|
||||
ticker.attach(60 * 60, Reuploaddata);
|
||||
write_log(log_path,10,"IS1 Init Success.");
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
log_data = "System Init Success";
|
||||
write_log(log_path,10,log_data);
|
||||
// Serial.println(gsmmanger->GetDataAndTime());
|
||||
}
|
||||
String lastdate="";
|
||||
void loop()
|
||||
{
|
||||
String Date = getnetData();
|
||||
String tem = fenge(Date," ",0);
|
||||
log_path = "/log/"+tem+".txt";
|
||||
// //擦除myport缓存
|
||||
// while (myPort.read() != -1)
|
||||
// ;
|
||||
// myPort.println("YULIANG#");
|
||||
// delay(510); //等待500ms
|
||||
// String yuliang=myPort.readStringUntil('#');
|
||||
// delay(1010);
|
||||
// Serial.println("yuliang "+yuliang);
|
||||
|
||||
/////////////////NOW/////////////////////
|
||||
write_log(log_path,10,"");
|
||||
write_log(log_path,10,Date);
|
||||
|
||||
String yuliang = String(myslave.getYuliang());
|
||||
delay(1010);
|
||||
Serial.println("yuliang "+yuliang);
|
||||
write_log(log_path,10,"getYuliang :"+yuliang);
|
||||
|
||||
// //擦除myport缓存
|
||||
// while (myPort.read() != -1)
|
||||
// ;
|
||||
// myPort.println("YLFZ#");
|
||||
// delay(510); //等待500ms
|
||||
// String yuliangfz=myPort.readStringUntil('#');
|
||||
// delay(1010);
|
||||
// Serial.println("fuzhao "+yuliangfz);
|
||||
|
||||
/////////////////NOW/////////////////////
|
||||
String yuliangfz = String(myslave.getYuliang());
|
||||
delay(1010);
|
||||
Serial.println("fuzhao " + yuliangfz);
|
||||
log_data ="fuzhao :"+yuliangfz;
|
||||
write_log(log_path,10,log_data);
|
||||
// while (myPort.read() != -1)
|
||||
// ;
|
||||
// myPort.println("WindSensor#"); //发送指令给无参数
|
||||
// delay(510); //等待500ms
|
||||
// for (int j = 0; j < 17; ++j)
|
||||
// {
|
||||
// windret[j] = myPort.read(); //读取返回倄1<E58084>71ᅣ1<EFBF84>77
|
||||
// // Serial.println(ret[j],HEX);
|
||||
// }
|
||||
// float VV = (windret[3] * 256 + windret[4]) * 1.0 / 100;
|
||||
// float DD = (windret[5] * 256 + windret[6]) * 1.0 / 10;
|
||||
// float TT = (windret[7] * 256 + windret[8]) * 1.0 / 100;
|
||||
// float HH = (windret[9] * 256 + windret[10]) * 1.0 / 100;
|
||||
// long PP = (windret[13] * 256 + windret[14]) * 256 * 256 + (windret[11] * 256 + windret[12]);
|
||||
// Serial.println("VV:" + String(VV) + "DD:" + String(DD) + "TT:" + String(TT) + "HH:" + String(HH) + "PP:" + String(PP));
|
||||
// //////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////NOW///////////////////////////
|
||||
myslave.getWehter();
|
||||
memcpy(windret,myslave.ret,17);
|
||||
float VV = (windret[3] * 256 + windret[4]) * 1.0 / 100;
|
||||
float DD = (windret[5] * 256 + windret[6]) * 1.0 / 10;
|
||||
float TT = (windret[7] * 256 + windret[8]) * 1.0 / 100;
|
||||
float HH = (windret[9] * 256 + windret[10]) * 1.0 / 100;
|
||||
long PP = (windret[13] * 256 + windret[14]) * 256 * 256 + (windret[11] * 256 + windret[12]);
|
||||
Serial.println("VV:" + String(VV) + "DD:" + String(DD) + "TT:" + String(TT) + "HH:" + String(HH) + "PP:" + String(PP));
|
||||
write_log(log_path,10,"VV:" + String(VV) + "DD:" + String(DD) + "TT:" + String(TT) + "HH:" + String(HH) + "PP:" + String(PP));
|
||||
|
||||
// //读取美创模块
|
||||
// delay(1010);
|
||||
// while (myPort.read() != -1)
|
||||
// ;
|
||||
// delay(1000); //等待1s 防止下位机反应不过来
|
||||
// myPort.println("MLX#");
|
||||
// delay(10);
|
||||
// for (int j = 0; j < 8; ++j)
|
||||
// {
|
||||
// ret[j] = myPort.read();
|
||||
// }
|
||||
// double temprature;
|
||||
// memcpy(&temprature, ret, 8);
|
||||
// Serial.println("wendu");
|
||||
// Serial.println(temprature);
|
||||
// delay(1000);
|
||||
|
||||
////////////////////////////NOW///////////////////////////
|
||||
String temprature =String(myslave.getMLX());
|
||||
Serial.println("wendu");
|
||||
Serial.println(temprature);
|
||||
log_data ="wendu :"+temprature;
|
||||
write_log(log_path,10,log_data);
|
||||
|
||||
////sim 循环
|
||||
|
||||
write_log(log_path,10,"start gsmmanger->loop()");
|
||||
gsmmanger->loop();
|
||||
#ifdef DINBIAO
|
||||
String Datenow1=getnetData();
|
||||
Datenow =fenge(Datenow1, " ", 0) + "_" + fenge(fenge(Datenow1, " ", 1), ":", 0) + "_" + fenge(fenge(Datenow1, " ", 1), ":", 1) + "_" + fenge(fenge(Datenow1, " ", 1), ":", 2);
|
||||
IS1Sensor.PrintFunc=printbytcp;
|
||||
#endif
|
||||
write_log(log_path,10,"start TakeOneJob()");
|
||||
IS1Sensor.TakeOneJob(); ////IS1采集一次
|
||||
String StationID = IS1Sensor.SensorInfo.serialnumber;
|
||||
String SensorID = IS1Sensor.SensorInfo.SensorName;
|
||||
|
||||
///////////////获取时间
|
||||
// while (myPort.read() != -1)
|
||||
// ;
|
||||
// myPort.println("GETGPS#");
|
||||
// String gpsbac = myPort.readStringUntil('\n');
|
||||
// Serial.println(gpsbac);
|
||||
|
||||
// String statnumberstr = fenge(gpsbac, "#", 1);
|
||||
// String statnumber = fenge(statnumberstr, "_", 1);
|
||||
// Serial.println(statnumber);
|
||||
// String Date;
|
||||
// if (statnumber.toInt() < 3)
|
||||
// {
|
||||
// Date = getnetData();
|
||||
// }
|
||||
|
||||
write_log(log_path,10,"start get_GPS()");
|
||||
String gpsbac = get_GPS();
|
||||
|
||||
Serial.println(gpsbac);
|
||||
// if (index < 28)
|
||||
// {
|
||||
write_log(log_path,10,"start getnetData()");
|
||||
Date = getnetData();
|
||||
// }
|
||||
|
||||
|
||||
// String Date;
|
||||
// Date = getnetData();
|
||||
|
||||
// str.substring(0, weizhi);
|
||||
// else
|
||||
// {
|
||||
// String datastr = fenge(gpsbac, "#", 0);
|
||||
// Date = fenge(datastr, "_", 1);
|
||||
// if (hassend == 0)
|
||||
// {
|
||||
// gpsbac = StationID+"#"+gpsbac;
|
||||
// int lennn = gpsbac.length();
|
||||
// char *temp = new char[lennn];
|
||||
// memcpy(temp, gpsbac.c_str(), gpsbac.length());
|
||||
// String nameoffile = "/gps/" + fenge(Date, " ", 0) + "_" + fenge(fenge(Date, " ", 1), ":", 0) + "_" + fenge(fenge(Date, " ", 1), ":", 1) + "_" + fenge(fenge(Date, " ", 1), ":", 2) + ".gps";
|
||||
// bool flagsucc = UpdateData("/weather/php/StationGPSinfo.php", temp, lennn);
|
||||
|
||||
// if (!flagsucc)
|
||||
// {
|
||||
// // sdcard::WriteStringToFile(nameoffile, temp, lennn);
|
||||
// }
|
||||
// else{
|
||||
// Serial.println("Finish Put StationGPSinfo Data");
|
||||
// }
|
||||
// delete[] temp;
|
||||
|
||||
// }
|
||||
// if (hassend >= 0)
|
||||
// {
|
||||
// hassend--;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// delay(15000);
|
||||
// if (fenge(Date, " ", 0)!=lastdate)
|
||||
// {
|
||||
// lastdate=fenge(Date, " ", 0);
|
||||
// while (myPort.read() != -1)
|
||||
// ;
|
||||
// myPort.println("ClearYL#");
|
||||
// ProgrameUper->CheckAndUpdate();
|
||||
|
||||
// /* code */
|
||||
// }
|
||||
// String Date;
|
||||
// double temprature;
|
||||
// String yuliang;
|
||||
// String yuliangfz;
|
||||
|
||||
|
||||
/////////*获取相关信息*//////////////////////////
|
||||
String datestring=fenge(Date, " ", 0) + "_" + fenge(fenge(Date, " ", 1), ":", 0) + "_" + fenge(fenge(Date, " ", 1), ":", 1) + "_" + fenge(fenge(Date, " ", 1), ":", 2);
|
||||
String Upheader = Date + "##" + StationID + "##" + SensorID + "##" + "UP" + "##"+String(IS1Sensor.shutterup)+"##";
|
||||
String Upname = "/up/" +datestring+ "_" + StationID + "_" + SensorID + "_" + "UP";
|
||||
String Downheader = Date + "##" + StationID + "##" + SensorID + "##" + "DOWN" + "##"+String(IS1Sensor.shutterdown)+"##";
|
||||
String Downname = "/down/" + datestring + "_" + StationID + "_" + SensorID + "_" + "DOWN";
|
||||
String senderID = Date + "##" + StationID + "##" + SensorID + "##" + String(temprature) + "##"+yuliang+"##"+yuliangfz+"##";
|
||||
String othername = "/other/" +datestring + "_" + StationID + "_" + SensorID + "_" + String(temprature);
|
||||
// Serial.println(senderID);
|
||||
// Serial.println( Upheader);
|
||||
// Serial.println(Upheader.length());
|
||||
|
||||
//////////////////////上传up数据//////////////////
|
||||
write_log(log_path,10,"put up data");
|
||||
size_t lennn = IS1Sensor.SensorInfo.BandNum * 2 + Upheader.length();
|
||||
char *temp = new char[IS1Sensor.SensorInfo.BandNum * 2 + Upheader.length()];
|
||||
memcpy(temp, Upheader.c_str(), Upheader.length());
|
||||
char *str=(char *)IS1Sensor.UpData;
|
||||
int lenofis=IS1Sensor.SensorInfo.BandNum * 2 ;
|
||||
for (size_t i = 0; i < IS1Sensor.SensorInfo.BandNum * 2; i++)
|
||||
{
|
||||
//temp[Upheader.length()+i]=str[i];
|
||||
}
|
||||
memcpy(temp + Upheader.length(), IS1Sensor.UpData,IS1Sensor.SensorInfo.BandNum * 2);
|
||||
bool flagsucc = UpdateData("/weather/php/SpectralDataUp.php", temp, lennn);
|
||||
vTaskDelay(3000);
|
||||
if (!flagsucc)
|
||||
{
|
||||
sdcard::WriteStringToFile(Upname, temp, lennn);
|
||||
log_data ="Up_data upload failed,save to SD.";
|
||||
write_log(log_path,10,log_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("finish Put Up Data");
|
||||
log_data ="finish Put Up Data.";
|
||||
write_log(log_path,10,log_data);
|
||||
}
|
||||
delete[] temp;
|
||||
|
||||
|
||||
|
||||
//////////////////////上传Down数据//////////////////
|
||||
write_log(log_path,10,"put dowm data");
|
||||
lennn = IS1Sensor.SensorInfo.BandNum * 2 + Downheader.length();
|
||||
temp = new char[lennn];
|
||||
memcpy(temp, Downheader.c_str(), Downheader.length());
|
||||
str=(char *)IS1Sensor.DownData;
|
||||
lenofis=IS1Sensor.SensorInfo.BandNum * 2 ;
|
||||
for (size_t i = 0; i < IS1Sensor.SensorInfo.BandNum * 2; i++)
|
||||
{
|
||||
// temp[Downheader.length()+i]=str[i];
|
||||
}
|
||||
memcpy(temp + Downheader.length(), IS1Sensor.DownData,IS1Sensor.SensorInfo.BandNum * 2);
|
||||
flagsucc = UpdateData("/weather/php/SpectralDataUp.php", temp, lennn);
|
||||
vTaskDelay(3000);
|
||||
|
||||
if (!flagsucc)
|
||||
{
|
||||
sdcard::WriteStringToFile(Downname, temp, lennn);
|
||||
log_data ="Down_data upload failed,save to SD.";
|
||||
write_log(log_path,10,log_data);
|
||||
}else{
|
||||
Serial.println("finish Put Down Data");
|
||||
log_data ="finish Put Down Data.";
|
||||
write_log(log_path,10,log_data);
|
||||
}
|
||||
delete[] temp;
|
||||
|
||||
//////////////////////上传其他数据//////////////////
|
||||
lennn = 12 + senderID.length();
|
||||
temp = new char[lennn];
|
||||
memcpy(temp, senderID.c_str(), senderID.length());
|
||||
memcpy(temp + senderID.length(), windret + 3, 12);
|
||||
flagsucc = UpdateData("/weather/php/WindsensorUp.php", temp, lennn, "application/json");
|
||||
vTaskDelay(3000);
|
||||
if (!flagsucc)
|
||||
{
|
||||
sdcard::WriteStringToFile(othername, temp, lennn);
|
||||
log_data ="put Other Data failed,save to SD.";
|
||||
write_log(log_path,10,log_data);
|
||||
}else{
|
||||
Serial.println("finish Put Other Data");
|
||||
log_data ="finish Put Other Data.";
|
||||
write_log(log_path,10,log_data);
|
||||
}
|
||||
delete[] temp;
|
||||
|
||||
|
||||
//结束并等待一定时间
|
||||
// http->stop(); delay(100);return;
|
||||
|
||||
delay(120000);
|
||||
#ifdef DINBIAO
|
||||
abort();
|
||||
ESP.restart();
|
||||
#endif
|
||||
return;
|
||||
|
||||
// //////以下位测试代砄1<E7A084>71ᅣ1<EFBF84>77
|
||||
|
||||
// delay(3000);
|
||||
// // int err = http->get("/weather/php/WindsensorUp.php");
|
||||
// // if (err == 0)
|
||||
// {
|
||||
// SerialMon.println(F("failed to connect"));
|
||||
// delay(10000);
|
||||
// return;
|
||||
// }
|
||||
// int status = http->responseStatusCode();
|
||||
// SerialMon.print(F("Response status code: "));
|
||||
// SerialMon.println(status);
|
||||
// if (!status)
|
||||
// {
|
||||
// delay(10000);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// SerialMon.println(F("Response Headers:"));
|
||||
// while (http->headerAvailable())
|
||||
// {
|
||||
// String headerName = http->readHeaderName();
|
||||
// String headerValue = http->readHeaderValue();
|
||||
// SerialMon.println(" " + headerName + " : " + headerValue);
|
||||
// }
|
||||
|
||||
// int length = http->contentLength();
|
||||
// if (length >= 0)
|
||||
// {
|
||||
// SerialMon.print(F("Content length is: "));
|
||||
// SerialMon.println(length);
|
||||
// }
|
||||
// if (http->isResponseChunked())
|
||||
// {
|
||||
// SerialMon.println(F("The response is chunked"));
|
||||
// }
|
||||
|
||||
// String body = http->responseBody();
|
||||
// SerialMon.println(F("Response:"));
|
||||
// SerialMon.println(body);
|
||||
|
||||
// SerialMon.print(F("Body length is: "));
|
||||
// SerialMon.println(body.length());
|
||||
// delay(5000);
|
||||
// // Shutdown
|
||||
|
||||
// // http->stop();
|
||||
}
|
||||
294
src/main.cpp1
Normal file
294
src/main.cpp1
Normal file
@ -0,0 +1,294 @@
|
||||
|
||||
/**************************************************************
|
||||
*
|
||||
* For this example, you need to install PubSubClient library:
|
||||
* https://github.com/knolleary/pubsubclient
|
||||
* or from http://librarymanager/all#PubSubClient
|
||||
*
|
||||
* TinyGSM Getting Started guide:
|
||||
* https://tiny.cc/tinygsm-readme
|
||||
*
|
||||
* For more MQTT examples, see PubSubClient library
|
||||
*
|
||||
**************************************************************
|
||||
* This example connects to HiveMQ's showcase broker.
|
||||
*
|
||||
* You can quickly test sending and receiving messages from the HiveMQ webclient
|
||||
* available at http://www.hivemq.com/demos/websocket-client/.
|
||||
*
|
||||
* Subscribe to the topic GsmClientTest/ledStatus
|
||||
* Publish "toggle" to the topic GsmClientTest/led and the LED on your board
|
||||
* should toggle and you should see a new message published to
|
||||
* GsmClientTest/ledStatus with the newest LED status.
|
||||
*
|
||||
**************************************************************/
|
||||
|
||||
// Select your modem:
|
||||
#define TINY_GSM_MODEM_SIM800
|
||||
// #define TINY_GSM_MODEM_SIM808
|
||||
// #define TINY_GSM_MODEM_SIM868
|
||||
// #define TINY_GSM_MODEM_SIM900
|
||||
// #define TINY_GSM_MODEM_SIM7000
|
||||
// #define TINY_GSM_MODEM_SIM7000SSL
|
||||
// #define TINY_GSM_MODEM_SIM7080
|
||||
// #define TINY_GSM_MODEM_SIM5360
|
||||
// #define TINY_GSM_MODEM_SIM7600
|
||||
// #define TINY_GSM_MODEM_UBLOX
|
||||
// #define TINY_GSM_MODEM_SARAR4
|
||||
// #define TINY_GSM_MODEM_M95
|
||||
// #define TINY_GSM_MODEM_BG96
|
||||
// #define TINY_GSM_MODEM_A6
|
||||
// #define TINY_GSM_MODEM_A7
|
||||
// #define TINY_GSM_MODEM_M590
|
||||
// #define TINY_GSM_MODEM_MC60
|
||||
// #define TINY_GSM_MODEM_MC60E
|
||||
// #define TINY_GSM_MODEM_ESP8266
|
||||
// #define TINY_GSM_MODEM_XBEE
|
||||
// #define TINY_GSM_MODEM_SEQUANS_MONARCH
|
||||
|
||||
// Set serial for debug console (to the Serial Monitor, default speed 115200)
|
||||
#define SerialMon Serial
|
||||
|
||||
// Set serial for AT commands (to the module)
|
||||
// Use Hardware Serial on Mega, Leonardo, Micro
|
||||
#include <TinyGsmClient.h>
|
||||
#include <PubSubClient.h>
|
||||
#ifndef __AVR_ATmega328P__
|
||||
HardwareSerial MySerial(1);
|
||||
#define SerialAT MySerial
|
||||
|
||||
// or Software Serial on Uno, Nano
|
||||
#else
|
||||
#include <SoftwareSerial.h>
|
||||
SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||
#endif
|
||||
|
||||
// See all AT commands, if wanted
|
||||
// #define DUMP_AT_COMMANDS
|
||||
|
||||
// Define the serial console for debug prints, if needed
|
||||
#define TINY_GSM_DEBUG SerialMon
|
||||
|
||||
// Range to attempt to autobaud
|
||||
// NOTE: DO NOT AUTOBAUD in production code. Once you've established
|
||||
// communication, set a fixed baud rate using modem.setBaud(#).
|
||||
#define GSM_AUTOBAUD_MIN 9600
|
||||
#define GSM_AUTOBAUD_MAX 115200
|
||||
|
||||
// Add a reception delay, if needed.
|
||||
// This may be needed for a fast processor at a slow baud rate.
|
||||
// #define TINY_GSM_YIELD() { delay(2); }
|
||||
|
||||
// Define how you're planning to connect to the internet.
|
||||
// This is only needed for this example, not in other code.
|
||||
#define TINY_GSM_USE_GPRS true
|
||||
#define TINY_GSM_USE_WIFI false
|
||||
|
||||
// set GSM PIN, if any
|
||||
#define GSM_PIN ""
|
||||
|
||||
// Your GPRS credentials, if any
|
||||
const char apn[] = "CMNET";
|
||||
const char gprsUser[] = "";
|
||||
const char gprsPass[] = "";
|
||||
|
||||
// Your WiFi connection credentials, if applicable
|
||||
const char wifiSSID[] = "YourSSID";
|
||||
const char wifiPass[] = "YourWiFiPass";
|
||||
|
||||
// MQTT details
|
||||
const char* broker = "broker.hivemq.com";
|
||||
|
||||
const char* topicLed = "GsmClientTest/led";
|
||||
const char* topicInit = "GsmClientTest/init";
|
||||
const char* topicLedStatus = "GsmClientTest/ledStatus";
|
||||
|
||||
|
||||
|
||||
// Just in case someone defined the wrong thing..
|
||||
#if TINY_GSM_USE_GPRS && not defined TINY_GSM_MODEM_HAS_GPRS
|
||||
#undef TINY_GSM_USE_GPRS
|
||||
#undef TINY_GSM_USE_WIFI
|
||||
#define TINY_GSM_USE_GPRS false
|
||||
#define TINY_GSM_USE_WIFI true
|
||||
#endif
|
||||
#if TINY_GSM_USE_WIFI && not defined TINY_GSM_MODEM_HAS_WIFI
|
||||
#undef TINY_GSM_USE_GPRS
|
||||
#undef TINY_GSM_USE_WIFI
|
||||
#define TINY_GSM_USE_GPRS true
|
||||
#define TINY_GSM_USE_WIFI false
|
||||
#endif
|
||||
|
||||
#ifdef DUMP_AT_COMMANDS
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#else
|
||||
TinyGsm modem(SerialAT);
|
||||
#endif
|
||||
TinyGsmClient client(modem);
|
||||
PubSubClient mqtt(client);
|
||||
|
||||
#define LED_PIN 13
|
||||
int ledStatus = LOW;
|
||||
|
||||
uint32_t lastReconnectAttempt = 0;
|
||||
|
||||
void mqttCallback(char* topic, byte* payload, unsigned int len) {
|
||||
SerialMon.print("Message arrived [");
|
||||
SerialMon.print(topic);
|
||||
SerialMon.print("]: ");
|
||||
SerialMon.write(payload, len);
|
||||
SerialMon.println();
|
||||
|
||||
// Only proceed if incoming message's topic matches
|
||||
if (String(topic) == topicLed) {
|
||||
ledStatus = !ledStatus;
|
||||
digitalWrite(LED_PIN, ledStatus);
|
||||
mqtt.publish(topicLedStatus, ledStatus ? "1" : "0");
|
||||
}
|
||||
}
|
||||
|
||||
boolean mqttConnect() {
|
||||
SerialMon.print("Connecting to ");
|
||||
SerialMon.print(broker);
|
||||
|
||||
// Connect to MQTT Broker
|
||||
boolean status = mqtt.connect("GsmClientTest");
|
||||
|
||||
// Or, if you want to authenticate MQTT:
|
||||
// boolean status = mqtt.connect("GsmClientName", "mqtt_user", "mqtt_pass");
|
||||
|
||||
if (status == false) {
|
||||
SerialMon.println(" fail");
|
||||
return false;
|
||||
}
|
||||
SerialMon.println(" success");
|
||||
mqtt.publish(topicInit, "GsmClientTest started");
|
||||
mqtt.subscribe(topicLed);
|
||||
return mqtt.connected();
|
||||
}
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
MySerial.begin(9600, SERIAL_8N1, 26, 14);
|
||||
// Set console baud rate
|
||||
SerialMon.begin(115200);
|
||||
delay(1010);
|
||||
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
|
||||
// !!!!!!!!!!!
|
||||
|
||||
pinMode(32, OUTPUT);
|
||||
digitalWrite(32, HIGH);
|
||||
Serial.println("Wait..."); pinMode(25, OUTPUT);
|
||||
pinMode(33, OUTPUT);
|
||||
digitalWrite(33, LOW);
|
||||
delay(1800);
|
||||
Serial.println("Wait...1");
|
||||
|
||||
digitalWrite(33, HIGH);
|
||||
// Set your reset, enable, power pins here
|
||||
// !!!!!!!!!!!
|
||||
Serial2.begin(9600);
|
||||
Serial.println("Wait...");
|
||||
// MySerial.begin(115200);
|
||||
delay(5000);
|
||||
MySerial.print("AT\r\n");
|
||||
MySerial.print("AT\r\n");
|
||||
MySerial.print("AT\r\n");
|
||||
MySerial.print("AT\r\n");
|
||||
String input = MySerial.readString();
|
||||
Serial.println(input);
|
||||
Serial.println("Wait..asdfasdf.");
|
||||
while (1)
|
||||
{
|
||||
input =MySerial.readString();
|
||||
Serial.println(input);
|
||||
MySerial.print("AT\r\n");
|
||||
delay(10);
|
||||
}
|
||||
|
||||
|
||||
delay(5000);
|
||||
|
||||
|
||||
//Serial2.begin(9600);
|
||||
//Serial2.print("AT\r\n");
|
||||
//delay(1000);
|
||||
|
||||
//input = Serial2.readString();
|
||||
//Serial.println(input);
|
||||
|
||||
delay(16000);
|
||||
// Set GSM module baud rate
|
||||
TinyGsmAutoBaud(SerialAT, 9600, 460800);
|
||||
// SerialAT.begin(9600);
|
||||
delay(6000);
|
||||
|
||||
// Restart takes quite some time
|
||||
// To skip it, call init() instead of restart()
|
||||
SerialMon.println("Initializing modem...");
|
||||
// modem.restart();
|
||||
modem.init();
|
||||
|
||||
String modemInfo = modem.getModemInfo();
|
||||
SerialMon.print("Modem Info: ");
|
||||
SerialMon.println(modemInfo);
|
||||
|
||||
#if TINY_GSM_USE_GPRS
|
||||
// Unlock your SIM card with a PIN if needed
|
||||
if (GSM_PIN && modem.getSimStatus() != 3) { modem.simUnlock(GSM_PIN); }
|
||||
#endif
|
||||
|
||||
#if TINY_GSM_USE_WIFI
|
||||
// Wifi connection parameters must be set before waiting for the network
|
||||
SerialMon.print(F("Setting SSID/password..."));
|
||||
if (!modem.networkConnect(wifiSSID, wifiPass)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" success");
|
||||
#endif
|
||||
|
||||
#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_XBEE
|
||||
// The XBee must run the gprsConnect function BEFORE waiting for network!
|
||||
modem.gprsConnect(apn, gprsUser, gprsPass);
|
||||
#endif
|
||||
|
||||
SerialMon.print("Waiting for network...");
|
||||
if (!modem.waitForNetwork()) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" success");
|
||||
|
||||
if (modem.isNetworkConnected()) { SerialMon.println("Network connected"); }
|
||||
|
||||
#if TINY_GSM_USE_GPRS
|
||||
// GPRS connection parameters are usually set after network registration
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(apn);
|
||||
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" success");
|
||||
|
||||
if (modem.isGprsConnected()) { SerialMon.println("GPRS connected"); }
|
||||
#endif
|
||||
|
||||
// MQTT Broker setup
|
||||
mqtt.setServer(broker, 1883);
|
||||
mqtt.setCallback(mqttCallback);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Make sure we're still registered on the network
|
||||
|
||||
}
|
||||
215
src/optoskybase.cpp
Normal file
215
src/optoskybase.cpp
Normal file
@ -0,0 +1,215 @@
|
||||
#include"optoskybase.h"
|
||||
static byte datatoget[10000];
|
||||
byte echtimedata[1000];
|
||||
OptoSky::OptoSky()
|
||||
{
|
||||
IsOptoskyinit=false;
|
||||
result=datatoget;
|
||||
}
|
||||
void OptoSky::SetPortName(int serial)
|
||||
{
|
||||
ISserial=new HardwareSerial(1);
|
||||
ISserial->begin(115200,SERIAL_8N1,17,18);
|
||||
// ISserial->println("sadfasdfsadfasdf");
|
||||
IsOptoskyinit=true;
|
||||
}
|
||||
void OptoSky::SendComment(byte *commend,int lenth)
|
||||
{
|
||||
unsigned short lenthsend = lenth + 5;
|
||||
byte *senddata=new byte[lenthsend]();
|
||||
|
||||
|
||||
senddata[0] = 0xaa;
|
||||
senddata[1] = 0x55;
|
||||
senddata[2] = (lenth+3) / 256;
|
||||
senddata[3] = (lenth+3) % 256;
|
||||
for (size_t i = 0; i < lenth; i++)
|
||||
{
|
||||
senddata[i+4]=commend[i];
|
||||
|
||||
/* code */
|
||||
}
|
||||
|
||||
int sum = 0;
|
||||
for (int i = 0; i < lenth+2; i++)
|
||||
{
|
||||
sum = sum+senddata[i+2];
|
||||
}
|
||||
senddata[lenthsend-1]=sum;
|
||||
if (IsOptoskyinit)
|
||||
{
|
||||
while (ISserial->read()!=-1)
|
||||
{
|
||||
/* code */
|
||||
|
||||
}
|
||||
//Serial.write(senddata,lenthsend);
|
||||
ISserial->write(senddata,lenthsend);
|
||||
delay(10);
|
||||
|
||||
}
|
||||
delete[] senddata;
|
||||
}
|
||||
|
||||
void OptoSky::SendComment(byte comid)
|
||||
{
|
||||
SendComment(&comid,1);
|
||||
}
|
||||
|
||||
void OptoSky::SendComment(byte *Comment,int commentlenth, byte *data,int lenth)
|
||||
{
|
||||
byte *commnetdsend=new byte[commentlenth+lenth]();
|
||||
memcpy(commnetdsend,Comment,commentlenth);
|
||||
memcpy(commnetdsend+commentlenth,data,lenth);
|
||||
SendComment(commnetdsend,commentlenth+lenth);
|
||||
delete[] commnetdsend;
|
||||
|
||||
}
|
||||
|
||||
void OptoSky::SendComment(byte comid, byte *data,int lenth)
|
||||
{
|
||||
byte *commnetdsend=new byte[lenth+1]();
|
||||
memcpy(commnetdsend,&comid,1);
|
||||
memcpy(commnetdsend+1,data,lenth);
|
||||
SendComment(commnetdsend,1+lenth);
|
||||
delete[] commnetdsend;
|
||||
}
|
||||
|
||||
bool OptoSky::GetReturn(byte id,int &lenth,int timewaitbefor)
|
||||
{
|
||||
if (!GetReturn(lenth,timewaitbefor))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (datatoget[4]!=id)
|
||||
{
|
||||
Serial.println("retrun is not correct with ComId:" );
|
||||
|
||||
return false;//<2F>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>0<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>0<EFBFBD>8<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>5<EFBFBD>3<EFBFBD>1<EFBFBD>2<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7<EFBFBD>1<EFBFBD>7
|
||||
}
|
||||
memcpy(datatoget,datatoget+5,lenth-1);
|
||||
lenth=lenth-6;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OptoSky::GetReturn(int &lenth,int timewaitbefor)
|
||||
{
|
||||
lenth=0;
|
||||
delay(timewaitbefor);
|
||||
while (ISserial->available())
|
||||
{
|
||||
int dataget=ISserial->readBytes(echtimedata,1000);
|
||||
|
||||
for (long i = 0; i < dataget; i++)
|
||||
{
|
||||
datatoget[i+lenth]=echtimedata[i];
|
||||
/* code */
|
||||
}
|
||||
lenth=lenth+dataget;
|
||||
|
||||
|
||||
|
||||
delay(40);
|
||||
|
||||
|
||||
/* code */
|
||||
}
|
||||
|
||||
|
||||
|
||||
int tiemstry=0;
|
||||
lable1:
|
||||
while (lenth < 5)
|
||||
{
|
||||
delay(20);
|
||||
if (ISserial->available())
|
||||
{
|
||||
/* code */
|
||||
int dataget=ISserial->readBytes(echtimedata,1000);
|
||||
|
||||
for (long i = 0; i < dataget; i++)
|
||||
{
|
||||
datatoget[i+lenth]=echtimedata[i];
|
||||
/* code */
|
||||
}
|
||||
lenth=lenth+dataget;
|
||||
}
|
||||
|
||||
if (tiemstry> 2000)
|
||||
{
|
||||
Serial.println("long time no data retrun");
|
||||
Serial.print("size now:");
|
||||
Serial.println(lenth);
|
||||
return false;
|
||||
|
||||
}
|
||||
tiemstry++;
|
||||
}
|
||||
if (datatoget[0] != 0xaa || datatoget[1] != 0x55)
|
||||
{
|
||||
memcpy(datatoget,datatoget+1,lenth-1);
|
||||
lenth--;
|
||||
|
||||
goto lable1;
|
||||
}
|
||||
|
||||
int datalenth = datatoget[2] * 256 + datatoget[3] + 2;
|
||||
tiemstry=0;
|
||||
while (lenth < datalenth)
|
||||
{
|
||||
delay(20);
|
||||
if (ISserial->available())
|
||||
{
|
||||
/* code */
|
||||
int dataget=ISserial->readBytes(echtimedata,1000);
|
||||
|
||||
for (long i = 0; i < dataget; i++)
|
||||
{
|
||||
datatoget[i+lenth]=echtimedata[i];
|
||||
/* code */
|
||||
}
|
||||
lenth=lenth+dataget;
|
||||
}
|
||||
if (tiemstry> 500)
|
||||
{
|
||||
Serial.println("not enouth data retrun");
|
||||
Serial.print("size now:");
|
||||
Serial.println(lenth);
|
||||
return false;
|
||||
|
||||
}
|
||||
tiemstry++;
|
||||
|
||||
}
|
||||
|
||||
if (lenth > datalenth)
|
||||
{
|
||||
lenth=datalenth;
|
||||
}
|
||||
int checkleth = datalenth - 3;
|
||||
unsigned int checknum = 0;
|
||||
for (size_t i = 0; i < checkleth; i++)
|
||||
{
|
||||
|
||||
checknum = checknum + datatoget[i + 2];
|
||||
}
|
||||
checknum = checknum % 256;
|
||||
if (checknum != datatoget[lenth-1])
|
||||
{
|
||||
Serial.println("checkerro " );
|
||||
//data.clear();
|
||||
//return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool OptoSky::isSensorInit()
|
||||
{
|
||||
return IsOptoskyinit;
|
||||
}
|
||||
77
src/optoskybase.h
Normal file
77
src/optoskybase.h
Normal file
@ -0,0 +1,77 @@
|
||||
|
||||
|
||||
#ifndef __OPTOSKYBASE_H__
|
||||
#define __OPTOSKYBASE_H__
|
||||
#include"HardwareSerial.h"
|
||||
|
||||
struct STRSensorInfo
|
||||
{
|
||||
String SensorName;
|
||||
long maxValue;
|
||||
long BandNum;
|
||||
String WavelenthStr;
|
||||
float *wavelenthlist;
|
||||
//double *wavelenth;
|
||||
bool isSensorInit;
|
||||
String serialnumber;
|
||||
float a1,a2,a3,a4;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define GET_MODEBOARD_TEMP 0x01
|
||||
#define GET_PN_NUMBER 0x03
|
||||
#define GET_SN_NUMBER 0x04
|
||||
#define GET_MANUFACTURE_DATA 0x06
|
||||
#define GET_MANUFACTOR_INFO 0x09
|
||||
#define GET_PIXEL_LENGTH 0x0a
|
||||
#define GET_TEC_TEMP 0x13
|
||||
#define SET_TEC_TEMP 0x12
|
||||
#define GET_OPTICFLAT_TEMP 0x35
|
||||
#define GET_CIRCUIT_BOARD_TEMP 0x36
|
||||
#define SET_INTEGRAL_TIME 0x14
|
||||
#define GET_INTEGRAL_TIME 0x41
|
||||
#define GET_MAX_INTEGRAL_TIME 0x42
|
||||
#define GET_MIN_INTEGRAL_TIME 0x43
|
||||
#define ASYNCHRONOUS_COLLECT_DARK 0x23
|
||||
#define ASYNCHRONOUS_START_COLLECTION 0x16
|
||||
#define ASYNCHRONOUS_READ_DATA 0x17
|
||||
#define SET_AVERAGE_NUMBER 0x28
|
||||
#define SYNCHRONIZATION_GET_DATA 0x1e
|
||||
#define SYNCHRONIZATION_GET_DARK 0x2f
|
||||
//#define SYNCHRONIZATION_GET_DARK 0x23
|
||||
#define EXTERNAL_TRIGGER_ENABLE 0x1f
|
||||
#define SET_XENON_LAMP_DELAY_TIME 0x24
|
||||
#define GET_WAVELENGTH_CALIBRATION_COFF 0x55
|
||||
#define GET_STAT_OF_LAMPOUT 0x60
|
||||
#define SET_GPIO 0x61
|
||||
#define byte u_char
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class OptoSky
|
||||
{
|
||||
public:
|
||||
OptoSky();
|
||||
byte *result;
|
||||
HardwareSerial *ISserial;
|
||||
bool IsOptoskyinit;
|
||||
void SetPortName(int serial);
|
||||
void SendComment(byte *commend,int lenth);
|
||||
void SendComment(byte comid);
|
||||
void SendComment(byte *Comment,int commentlenth, byte *data,int lenth);
|
||||
void SendComment(byte comid, byte *data,int lenth);
|
||||
bool GetReturn(byte id,int &lenth,int timewaitbefor=20);
|
||||
bool GetReturn(int &lenth,int timewaitbefor);
|
||||
|
||||
bool isSensorInit();
|
||||
void RemoveHeaderandEnd(byte *data,int lenth);
|
||||
|
||||
};
|
||||
#endif // __OPTOSKYBASE_H__
|
||||
120
src/slave.cpp
Normal file
120
src/slave.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
#include "slave.h"
|
||||
|
||||
double new_emissivity =0.95;
|
||||
|
||||
|
||||
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
|
||||
TwoWire wireme(0);
|
||||
|
||||
u_char a[]={0x01,0x04,0x00,0x00,0x00 ,0x06,0x70,0x08};
|
||||
u_char yuliang[]={0x02, 0x03, 0x00, 0x00 ,0x00, 0x01, 0x84, 0x39};
|
||||
u_char ClearYL[]={0x02,0x06,0x00, 0x00 ,0x00 ,0x5A ,0X09 ,0Xc2};
|
||||
u_char yuliangfuliangdu[]={0x02,0x03,0x00,0x02,0x00,0x02,0x65,0xf8};
|
||||
|
||||
u_char openGNRMC[]={0xF1,0xD9,0x06,0x01,0x03,0x00,0xF0,0x05,0x01,0x00,0x1A};
|
||||
u_char gpsSaveConfig[]={0xF1,0xD9,0x06,0x09,0x08,0x00,0x00,0x00,0x00,0x00,0x2F,0x00,0x00,0x00,0x46,0xB7};
|
||||
|
||||
|
||||
|
||||
SoftwareSerial *my485Port;
|
||||
void slave::init(int8_t MY485PORT_RX,int8_t MY485PORT_TX){
|
||||
// put your setup code here, to run once:
|
||||
//Wire.begin(4,5);
|
||||
|
||||
Serial.println("slave init ...");
|
||||
my485Port = new SoftwareSerial(MY485PORT_RX ,MY485PORT_TX,false);
|
||||
my485Port->begin(9600, SWSERIAL_8N1, MY485PORT_RX, MY485PORT_TX, false);
|
||||
|
||||
///////////// 光谱电源控制,重启
|
||||
pinMode(36,OUTPUT);
|
||||
digitalWrite(36,LOW);
|
||||
delay(2000);
|
||||
digitalWrite(36,HIGH);
|
||||
|
||||
|
||||
// GPSSeiral.begin(115200, SWSERIAL_8N1, 2, 12, false);
|
||||
wireme.setPins(7,8);
|
||||
|
||||
if (!mlx.begin(MLX90614_I2CADDR,&wireme)) {
|
||||
Serial.println("Error connecting to MLX sensor. Check wiring.");
|
||||
//while (1);
|
||||
};
|
||||
mlx.writeEmissivity(new_emissivity); // this does the 0x0000 erase write
|
||||
Serial.println(sizeof(openGNRMC));
|
||||
|
||||
}
|
||||
|
||||
double slave::getMLX(){
|
||||
double a =mlx.readObjectTempC();
|
||||
return a;
|
||||
// Serial.write((char*) &a,8);
|
||||
}
|
||||
|
||||
void slave::getWehter(){
|
||||
while (my485Port->read()!=-1);
|
||||
my485Port->write(a,8);
|
||||
delay(90);
|
||||
for (int j = 0; j <17 ; ++j) {
|
||||
ret[j]=my485Port->read();
|
||||
}
|
||||
float VV=(ret[3]*256+ret[4])*1.0/100;
|
||||
float DD=(ret[5]*256+ret[6])*1.0/10;
|
||||
float TT=(ret[7]*256+ret[8])*1.0/100;
|
||||
float HH=(ret[9]*256+ret[10])*1.0/100;
|
||||
long PP=(ret[13]*256+ret[14])*256*256+(ret[11]*256+ret[12]);
|
||||
#ifdef DEBG
|
||||
String str_getWehter = "VV:"+String(VV)+" DD:"+String(DD)+" TT:"+String(TT)+" HH:"+String(HH)+" PP:"+String(PP);
|
||||
// return str;
|
||||
// Serial.println("VV:"+String(VV)+" DD:"+String(DD)+" TT:"+String(TT)+" HH:"+String(HH)+" PP:"+String(PP));
|
||||
#endif
|
||||
// Serial.write(ret,17);
|
||||
}
|
||||
|
||||
float slave::getYuliang(){
|
||||
while (my485Port->read()!=-1);
|
||||
my485Port->write(yuliang,8);
|
||||
delay(90);
|
||||
|
||||
for (int j = 0; j <7; ++j) {
|
||||
ret[j]=my485Port->read();
|
||||
}
|
||||
float Value=ret[3]*256+ret[4];
|
||||
Value=Value/10;
|
||||
// Serial.write(ret,7);
|
||||
// Serial.print(Value);
|
||||
// Serial.print("#");
|
||||
|
||||
return Value;
|
||||
|
||||
}
|
||||
|
||||
int32_t slave::getYuliangfuliang(){
|
||||
while (my485Port->read()!=-1);
|
||||
my485Port->write(yuliangfuliangdu,8);
|
||||
delay(90);
|
||||
|
||||
for (int j = 0; j <7; ++j) {
|
||||
ret[j]=my485Port->read();
|
||||
}
|
||||
int32_t Value=(ret[3]*256+ret[4])*256*256+ret[5]*256+ret[6];
|
||||
// Value=Value/10;
|
||||
// Serial.write(ret,7);
|
||||
// Serial.print(Value);
|
||||
// Serial.print("#");
|
||||
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// 返回1,表示ok
|
||||
uint8_t slave::claeryuliang(){
|
||||
while (my485Port->read()!=-1);
|
||||
my485Port->write(ClearYL,8);
|
||||
delay(90);
|
||||
for (int j = 0; j <8; ++j) {
|
||||
ret[j]=my485Port->read();
|
||||
}
|
||||
// Serial.print("OK");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
30
src/slave.h
Normal file
30
src/slave.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef _SLAVE_H_
|
||||
#define _SLAVE_H_
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "SoftwareSerial.h"
|
||||
#include "Wire.h"
|
||||
#include <Adafruit_MLX90614.h>
|
||||
//#define DEBUG_SERIAL Serial
|
||||
#include <SPI.h>
|
||||
#include "SparkFun_Ublox_Arduino_Library.h"
|
||||
|
||||
|
||||
class slave
|
||||
{
|
||||
public:
|
||||
u_char ret[17];
|
||||
String str_getWehter;
|
||||
|
||||
void init(int8_t MYPORT_RX,int8_t MYPORT_TX);
|
||||
double getMLX();
|
||||
void getWehter();
|
||||
float getYuliang();
|
||||
int32_t getYuliangfuliang();
|
||||
uint8_t claeryuliang();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
233
src/updatebyme.cpp
Normal file
233
src/updatebyme.cpp
Normal file
@ -0,0 +1,233 @@
|
||||
#include "updatebyme.h"
|
||||
#include "SDmanger.h"
|
||||
void UpDateClassByme::performUpdate(Stream &updateSource, size_t updateSize)
|
||||
{
|
||||
if (Update.begin(updateSize))
|
||||
{
|
||||
Serial.println("Writes : ");
|
||||
size_t written = Update.writeStream(updateSource);
|
||||
if (written == updateSize)
|
||||
{
|
||||
Serial.println("Writes : " + String(written) + " successfully");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Written only : " + String(written) + "/" + String(updateSize) + ". Retry?");
|
||||
}
|
||||
if (Update.end())
|
||||
{
|
||||
Serial.println("OTA finished!");
|
||||
if (Update.isFinished())
|
||||
{
|
||||
Serial.println("Restart ESP device!");
|
||||
abort();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("OTA not fiished");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Error occured #: " + String(Update.getError()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Cannot beggin update");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
size_t UpDateClassByme::DownloadFirmwareForurl(String version)
|
||||
{
|
||||
String url="/weather/firmware/esp32/firmware_"+version+".bin";
|
||||
int err = http->get(url.c_str());
|
||||
if (err != 0)
|
||||
{
|
||||
Serial.println(F("Date failed to connect"));
|
||||
delay(10000);
|
||||
return 0;
|
||||
}
|
||||
int status = http->responseStatusCode();
|
||||
if (!status)
|
||||
{
|
||||
delay(10000);
|
||||
return 0;
|
||||
}
|
||||
Serial.print(F("Response status code: "));
|
||||
Serial.println(status);
|
||||
// SerialMon.println(F("Response Headers:"));
|
||||
size_t count=0;
|
||||
while (http->headerAvailable())
|
||||
{
|
||||
String headerName = http->readHeaderName();
|
||||
String headerValue = http->readHeaderValue();
|
||||
Serial.println("Date: " + headerName + " : " + headerValue);
|
||||
if (headerName=="Content-Length")
|
||||
{
|
||||
count=headerValue.toInt();
|
||||
/* code */
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Serial.println("lenth is "+String(count));
|
||||
if (http->isResponseChunked())
|
||||
{
|
||||
Serial.println(F("Date The response is chunked"));
|
||||
}
|
||||
char *str=new char[1000];
|
||||
int lent=count/1000;
|
||||
File file;
|
||||
|
||||
file = SD_MMC.open("/update.bin", "wb");
|
||||
|
||||
for (size_t i = 0; i < lent; i++)
|
||||
{
|
||||
http->readBytes(str,1000);
|
||||
file.write((const byte *)str,1000);
|
||||
Serial.print("download ");
|
||||
Serial.println(String(i*100/lent));
|
||||
/* code */
|
||||
}
|
||||
http->readBytes(str,count%1000);
|
||||
file.write((const byte *)str,count%1000);
|
||||
file.flush();
|
||||
file.close();
|
||||
//performUpdate(*http,cout);
|
||||
|
||||
|
||||
// http->readBytes
|
||||
Serial.println("adfasdfsadfsdfsd");
|
||||
//Serial.write(str,cout);
|
||||
//Serial.println(body.length());
|
||||
http->stop();
|
||||
return count;
|
||||
// return body;
|
||||
}
|
||||
|
||||
void UpDateClassByme::initme(String Version)
|
||||
{
|
||||
CurrentVersion=Version;
|
||||
|
||||
}
|
||||
void UpDateClassByme::updateversion()
|
||||
{
|
||||
String Targetversion=GetValueFromNet("/weather/php/upVserion.php",StationID+":"+CurrentVersion);
|
||||
}
|
||||
bool UpDateClassByme::CheckAndUpdate()
|
||||
{
|
||||
|
||||
|
||||
String Targetversion=GetValueFromNet("/weather/php/GetVserion.php",StationID);
|
||||
if ( Targetversion=="0"||Targetversion==CurrentVersion||Targetversion=="")
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
Serial.println("targetvesion is:"+Targetversion);
|
||||
|
||||
//size_t countdownload1=375584;
|
||||
size_t countdownload1=DownloadFirmwareForurl(Targetversion);
|
||||
if (countdownload1<10000)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Serial.println("count download is:"+String(countdownload1));
|
||||
|
||||
String MD5=GetValueFromNet("/weather/php/GetMD5Value.php",Targetversion);
|
||||
|
||||
if (MD5=="0")
|
||||
{
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
// updater.setMD5(MD5);
|
||||
MD5Builder md5my;
|
||||
|
||||
|
||||
File file;
|
||||
|
||||
file = SD_MMC.open("/update.bin", "rb");
|
||||
md5my.begin();
|
||||
md5my.addStream(file,countdownload1);
|
||||
md5my.calculate();
|
||||
String md5com=md5my.toString();
|
||||
Serial.println("md5 comput is:"+md5my.toString());
|
||||
Serial.println("md5 should is:"+MD5);
|
||||
file.close();
|
||||
if (MD5==md5com)
|
||||
{
|
||||
file = SD_MMC.open("/update.bin", "rb");
|
||||
performUpdate(file,countdownload1);
|
||||
return true;
|
||||
/* code */
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
UpDateClassByme::UpDateClassByme(HttpClient *httptm)
|
||||
{
|
||||
http=httptm;
|
||||
StationID="000";
|
||||
}
|
||||
String UpDateClassByme::GetValueFromNet(String url,String Key)
|
||||
{
|
||||
|
||||
http->beginRequest();
|
||||
http->post(url.c_str());
|
||||
|
||||
|
||||
http->sendHeader(HTTP_HEADER_CONTENT_LENGTH, Key.length());
|
||||
http->endRequest();
|
||||
int err = http->write((const byte *)Key.c_str(), Key.length());
|
||||
Serial.print("send date size");
|
||||
Serial.println(err);
|
||||
|
||||
if (err == 0)
|
||||
{
|
||||
|
||||
http->stop();
|
||||
return "-1";
|
||||
}
|
||||
int status = http->responseStatusCode();
|
||||
if (!status)
|
||||
{
|
||||
http->stop();
|
||||
return "-1";
|
||||
}
|
||||
|
||||
int length = http->contentLength();
|
||||
if (length == 0)
|
||||
{
|
||||
http->stop();
|
||||
return "-1";
|
||||
}
|
||||
|
||||
String body = http->responseBody();
|
||||
Serial.println("body:"+body);
|
||||
|
||||
http->stop();
|
||||
return body;
|
||||
}
|
||||
23
src/updatebyme.h
Normal file
23
src/updatebyme.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef UPDATEBYME_H
|
||||
#define UPDATEBYME_H
|
||||
#include<Update.h>
|
||||
#include <HTTPClient.h>
|
||||
class UpDateClassByme{
|
||||
public:
|
||||
UpdateClass updater;
|
||||
UpDateClassByme(HttpClient *httptm);
|
||||
void performUpdate(Stream &updateSource, size_t updateSize);
|
||||
HttpClient *http;
|
||||
size_t DownloadFirmwareForurl(String version);
|
||||
String CurrentVersion;
|
||||
void initme(String Version);
|
||||
bool CheckAndUpdate();
|
||||
String StationID;
|
||||
String GetValueFromNet(String url,String Key);
|
||||
void updateversion();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
41
src/wifidebug.cpp
Normal file
41
src/wifidebug.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <wifidebug.h>
|
||||
#include<TCPserver.h>
|
||||
|
||||
|
||||
|
||||
#ifdef DebugCalibration
|
||||
const char *ssid = "SmartForCalibration";
|
||||
const char *password = "123456789";
|
||||
IPAddress local_IP(192, 168, 1,2);
|
||||
IPAddress gateway(192, 168, 1, 2);
|
||||
IPAddress subnet(255, 255, 255, 0);
|
||||
TCPserver *tcpserver;
|
||||
void beginWIFI(){
|
||||
tcpserver=new TCPserver(23);
|
||||
WiFi.mode( WIFI_MODE_AP );
|
||||
Serial.println("init webserver ok 33333");
|
||||
WiFi.softAPConfig(local_IP, gateway, subnet);
|
||||
boolean result = WiFi.softAP(ssid, password);
|
||||
|
||||
tcpserver->loop();
|
||||
|
||||
}
|
||||
void tcploop(){
|
||||
tcpserver->loop();
|
||||
}
|
||||
|
||||
|
||||
void printbytcpserver(String str)
|
||||
{
|
||||
tcpserver->SendDataToClinet(str);
|
||||
tcpserver->loop();
|
||||
// Serial.println(str);
|
||||
|
||||
}
|
||||
#endif
|
||||
#ifndef DebugCalibration
|
||||
void beginWIFI(){}
|
||||
void printbytcpserver(String str){}
|
||||
void tcploop(){}
|
||||
#endif
|
||||
|
||||
16
src/wifidebug.h
Normal file
16
src/wifidebug.h
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
#include"Arduino.h"
|
||||
#include"Define.h"
|
||||
#ifdef DebugCalibration
|
||||
#include"WiFi.h"
|
||||
#endif
|
||||
|
||||
void beginWIFI();
|
||||
void printbytcpserver(String str);
|
||||
void tcploop();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user