v2.9
This commit is contained in:
11
src/Define.h
11
src/Define.h
@ -1,10 +1,19 @@
|
||||
#ifndef Define_h
|
||||
#define Define_h
|
||||
#define STRINGIFY(x) #x
|
||||
#define TOSTRING(x) STRINGIFY(x)
|
||||
// #define ARDUINO_USB_MODE 0
|
||||
|
||||
|
||||
//#define DebugCalibration
|
||||
//#define DINBIAO
|
||||
//#define Curentvsion "V2.4b"\
|
||||
#define Curentvsion "V2.5b"
|
||||
#define Curentvsion "V2.3"
|
||||
#define TINY_GSM_DEBUG Serial
|
||||
#ifndef Curentvsion
|
||||
#define Curentvsion TOSTRING(VERSION)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -2,16 +2,35 @@
|
||||
HardwareSerial *MySerial;
|
||||
GSMMannger::GSMMannger(int serialnumber, int rx, int tx)
|
||||
{
|
||||
MySerial=new HardwareSerial(serialnumber);
|
||||
m_serialnumber = serialnumber;
|
||||
m_rx = rx;
|
||||
m_tx = tx;
|
||||
|
||||
}
|
||||
|
||||
bool GSMMannger::setpu()
|
||||
{
|
||||
MySerial=new HardwareSerial(m_serialnumber);
|
||||
Serial.println("Wait...123123");
|
||||
modem = new TinyGsm(*MySerial);
|
||||
MySerial->begin(115200, SERIAL_8N1, rx, tx);
|
||||
MySerial->begin(115200, SERIAL_8N1, m_rx, m_tx);
|
||||
client = new TinyGsmClient(*modem);
|
||||
// !!!!!!!!!!! <20>ϵ<EFBFBD>
|
||||
Serial.println("Wait...");
|
||||
|
||||
#if ARDUINO_USB_CDC_ON_BOOT
|
||||
pinMode(37, OUTPUT); //pin32控制sim800C电源 高电平上电 低电平断电
|
||||
digitalWrite(37, LOW);
|
||||
delay(100);
|
||||
digitalWrite(37, HIGH);
|
||||
#else
|
||||
|
||||
|
||||
pinMode(37, OUTPUT); //pin32控制sim800C电源 高电平上电 低电平断电
|
||||
digitalWrite(37, HIGH);
|
||||
delay(100);
|
||||
digitalWrite(37, LOW);
|
||||
#endif
|
||||
Serial.println("Wait...1");
|
||||
delay(1800);
|
||||
// Set your reset, enable, power pins here
|
||||
@ -20,11 +39,11 @@ GSMMannger::GSMMannger(int serialnumber, int rx, int tx)
|
||||
delay(5000);
|
||||
// Set GSM module baud rate
|
||||
// MySerial->readString();
|
||||
int banddd=TinyGsmAutoBaud(*MySerial, rx, tx, 9600,460800);
|
||||
int banddd=TinyGsmAutoBaud(*MySerial, m_rx, m_tx, 9600,460800);
|
||||
if (banddd==0)
|
||||
{
|
||||
Serial.println("fail to connect sim800 reboot");
|
||||
esp_restart();
|
||||
return false;
|
||||
/* code */
|
||||
}
|
||||
|
||||
@ -36,7 +55,7 @@ GSMMannger::GSMMannger(int serialnumber, int rx, int tx)
|
||||
if (modemInfo=="")
|
||||
{
|
||||
Serial.println("fail to getmode reboot");
|
||||
esp_restart();
|
||||
return false;
|
||||
/* code */
|
||||
}
|
||||
Serial.print("Modem Info: ");
|
||||
@ -51,7 +70,7 @@ GSMMannger::GSMMannger(int serialnumber, int rx, int tx)
|
||||
{
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
SerialMon.println(" success");
|
||||
|
||||
@ -65,7 +84,7 @@ GSMMannger::GSMMannger(int serialnumber, int rx, int tx)
|
||||
{
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
SerialMon.println(" success");
|
||||
|
||||
@ -74,6 +93,7 @@ GSMMannger::GSMMannger(int serialnumber, int rx, int tx)
|
||||
SerialMon.println("GPRS connected");
|
||||
}
|
||||
modem->NTPServerSync();
|
||||
return true;
|
||||
}
|
||||
String GSMMannger::I2toS(int n)
|
||||
{
|
||||
|
@ -1,4 +1,10 @@
|
||||
#if ARDUINO_USB_CDC_ON_BOOT
|
||||
|
||||
#define TINY_GSM_MODEM_BG96
|
||||
#else
|
||||
#define TINY_GSM_MODEM_SIM800
|
||||
//
|
||||
#endif
|
||||
#define SerialMon Serial
|
||||
#include <TinyGsmClient.h>
|
||||
#include <PubSubClient.h>
|
||||
@ -12,7 +18,7 @@
|
||||
|
||||
#define GSM_PIN ""
|
||||
|
||||
const char apn[] = "CMNET";
|
||||
const char apn[] = "cmiot";
|
||||
const char gprsUser[] = "";
|
||||
const char gprsPass[] = "";
|
||||
|
||||
@ -20,6 +26,7 @@ class GSMMannger
|
||||
{
|
||||
public:
|
||||
GSMMannger(int serialnumber,int rx,int tx); // <20><><EFBFBD>ǹ<EFBFBD><C7B9>캯<EFBFBD><ECBAAF>
|
||||
bool setpu();
|
||||
TinyGsm *modem;
|
||||
TinyGsmClient *client;
|
||||
String GetDataAndTime();
|
||||
@ -27,6 +34,10 @@ class GSMMannger
|
||||
String I2toS(int n);
|
||||
int year,month, day, hour,minute, second;
|
||||
float timezone;
|
||||
private:
|
||||
int m_serialnumber;
|
||||
int m_rx;
|
||||
int m_tx;
|
||||
|
||||
};
|
||||
|
||||
|
234
src/Myhttpserver.cpp
Normal file
234
src/Myhttpserver.cpp
Normal file
@ -0,0 +1,234 @@
|
||||
#include"Myhttpserver.h"
|
||||
myHttpServer * myhttpserver;
|
||||
|
||||
|
||||
String myHttpServer::getnetData()
|
||||
{
|
||||
if (!isinit)
|
||||
{
|
||||
return "fail";
|
||||
}
|
||||
|
||||
//http->beginRequest();
|
||||
int timetryget = 0;
|
||||
labelloop:
|
||||
write_log(log_path,100,"http->get11111");
|
||||
|
||||
int err = http1->get("/weather/php/Date.php");
|
||||
if (err != 0)
|
||||
{
|
||||
// SerialMon.println(F("Date failed to connect"));
|
||||
// delay(10000);
|
||||
|
||||
write_log(log_path,100,"Date failed to connect"+String(err));
|
||||
vTaskDelay(10000);
|
||||
|
||||
esp_restart();
|
||||
return "";
|
||||
}
|
||||
write_log(log_path,100,"http->responseStatusCode222");
|
||||
int status = http1->responseStatusCode();
|
||||
if (!status)
|
||||
{
|
||||
vTaskDelay(10000);
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
// SerialMon.println(F("Response Headers:"));
|
||||
write_log(log_path,100,"http->headerAvailable333");
|
||||
int times_try = 0;
|
||||
while (http1->headerAvailable())
|
||||
{
|
||||
|
||||
if(times_try > 50)
|
||||
{
|
||||
write_log(log_path,100,"http->headerAvailable failed ...");
|
||||
http1->stop();
|
||||
if (timetryget++ > 5)
|
||||
{
|
||||
write_log(log_path,100,"http->headerAvailable failed than 5 times ... return error");
|
||||
return "error";
|
||||
}
|
||||
|
||||
|
||||
goto labelloop;
|
||||
}
|
||||
write_log(log_path,100,"http->readHeaderName");
|
||||
String headerName = http1->readHeaderName();
|
||||
write_log(log_path,100,"http->readHeaderValue");
|
||||
String headerValue = http1->readHeaderValue();
|
||||
write_log(log_path,100,String(times_try)+"http->headerName "+headerName);
|
||||
write_log(log_path,100,String(times_try)+"http->headerValue "+headerValue);
|
||||
// SerialMon.println("Date: " + headerName + " : " + headerValue);
|
||||
vTaskDelay(100);
|
||||
times_try++;
|
||||
}
|
||||
write_log(log_path,100,"http->isResponseChunked4444");
|
||||
if (http1->isResponseChunked())
|
||||
{
|
||||
// SerialMon.println(F("Date The response is chunked"));
|
||||
}
|
||||
write_log(log_path,100,"http->responseBody555");
|
||||
String body = http1->responseBody();
|
||||
http1->stop();
|
||||
return body;
|
||||
}
|
||||
|
||||
bool myHttpServer::UpdateData(String path, char *str, size_t lenth, String Contenttype )
|
||||
{
|
||||
if (!isinit)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
http1->beginRequest();
|
||||
http1->post(path);
|
||||
if (Contenttype != "")
|
||||
{
|
||||
http1->sendHeader(HTTP_HEADER_CONTENT_TYPE, Contenttype);
|
||||
|
||||
/* code */
|
||||
}
|
||||
|
||||
http1->sendHeader(HTTP_HEADER_CONTENT_LENGTH, lenth);
|
||||
http1->endRequest();
|
||||
int err = http1->write((const byte *)str, lenth);
|
||||
delay(100);
|
||||
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)
|
||||
{
|
||||
http1->stop();
|
||||
return false;
|
||||
}
|
||||
int status = http1->responseStatusCode();
|
||||
// Serial.println("hear3");
|
||||
if (!status)
|
||||
{
|
||||
http1->stop();
|
||||
return false;
|
||||
}
|
||||
|
||||
int length = http1->contentLength();
|
||||
// Serial.println("hear4");
|
||||
if (length == 0)
|
||||
{
|
||||
http1->stop();
|
||||
return false;
|
||||
}
|
||||
|
||||
String body = http1->responseBody();
|
||||
Serial.println("body:"+body);
|
||||
if (body != "ok")
|
||||
{
|
||||
http1->stop();
|
||||
return false;
|
||||
}
|
||||
|
||||
http1->stop();
|
||||
return true;
|
||||
}
|
||||
void myHttpServer::ReuploadData(String path, String webpath, String content )
|
||||
{
|
||||
if (!isinit)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void Reuploaddata1(void *) //重新上传数据
|
||||
{
|
||||
myhttpserver->ReuploadData("/down", "/weather/php/SpectralDataUp.php");
|
||||
myhttpserver->ReuploadData("/up", "/weather/php/SpectralDataUp.php");
|
||||
myhttpserver->ReuploadData("/other", "/weather/php/WindsensorUp.php", "application/json");
|
||||
}
|
||||
void Reuploaddata2() //重新上传数据
|
||||
{
|
||||
myhttpserver->ReuploadData("/down", "/weather/php/SpectralDataUp.php");
|
||||
myhttpserver->ReuploadData("/up", "/weather/php/SpectralDataUp.php");
|
||||
myhttpserver->ReuploadData("/other", "/weather/php/WindsensorUp.php", "application/json");
|
||||
}
|
||||
|
||||
void myHttpServer::setup1(Client &client,char * serveradd)
|
||||
{
|
||||
|
||||
http1 = new HttpClient(client, serveradd,80);
|
||||
|
||||
isinit = true;
|
||||
log_path = "/httplog.txt";
|
||||
myhttpserver= this;
|
||||
Serial.println("start httpserver 2332213"+String(http1->iServerName));
|
||||
}
|
28
src/Myhttpserver.h
Normal file
28
src/Myhttpserver.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef MYHTTPSERVER_H
|
||||
#define MYHTTPSERVER_H
|
||||
#define LOGGING
|
||||
#include <Arduino.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <ArduinoHttpClient.h>
|
||||
#include "log.h"
|
||||
void Reuploaddata1(void *);
|
||||
void Reuploaddata2() ;
|
||||
class myHttpServer
|
||||
{
|
||||
public:
|
||||
String getnetData();
|
||||
bool UpdateData(String path, char *str, size_t lenth, String Contenttype = "");
|
||||
void ReuploadData(String path, String webpath, String content = "");
|
||||
|
||||
|
||||
void setup1(Client &client,char * serveradd);
|
||||
HttpClient *http1;
|
||||
private:
|
||||
|
||||
String log_path;
|
||||
bool isinit = false;
|
||||
bool ishttpbusy = false;
|
||||
};
|
||||
// Add your code here
|
||||
|
||||
#endif
|
@ -18,7 +18,7 @@ int sdcard::init_sdcard()
|
||||
} else {
|
||||
Serial.println("UNKNOWN");
|
||||
}
|
||||
|
||||
|
||||
uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
|
||||
Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize);
|
||||
|
||||
|
@ -8,6 +8,13 @@
|
||||
#include "SensorOptoSky.h"
|
||||
bool SensorOptoSky::initSensor(int id )
|
||||
{
|
||||
|
||||
|
||||
// pinMode(36,INPUT);
|
||||
delay(1000);
|
||||
pinMode(36,OUTPUT);
|
||||
digitalWrite(36,HIGH);
|
||||
;
|
||||
IS1Sensor.SetPortName(id);
|
||||
SensorInfo=GetSensorInfo();
|
||||
pinMode(5,OUTPUT);
|
||||
@ -38,6 +45,15 @@ STRSensorInfo SensorOptoSky::GetSensorInfo() {
|
||||
delete[] result;
|
||||
str.remove(str.indexOf("00")+1,str.length()-(str.indexOf("00")+1));
|
||||
setem.SensorName=str;
|
||||
if(setem.SensorName=="")
|
||||
{
|
||||
setem.SensorName=="ATP1010";
|
||||
}
|
||||
#ifdef DINBIAO
|
||||
|
||||
setem.SensorName="ATP1010";
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
IS1Sensor.SendComment(GET_SN_NUMBER);
|
||||
|
@ -23,7 +23,7 @@ private:
|
||||
public:
|
||||
|
||||
|
||||
#if ARDUINO_USB_CDC_ON_BOOT && !ARDUINO_USB_MODE //Serial used for USB CDC
|
||||
#if ARDUINO_USB_CDC_ON_BOOT && !ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC
|
||||
USBCDC *myserial;
|
||||
TCPserver(USBCDC *serial,int port);
|
||||
#elif ARDUINO_USB_CDC_ON_BOOT && ARDUINO_USB_MODE
|
||||
|
14
src/log.cpp
14
src/log.cpp
@ -38,6 +38,20 @@ void write_log(String path,unsigned char level,String write_data)
|
||||
//保存本地,和同时上传云端,小于10只保存本地
|
||||
}
|
||||
|
||||
unsigned long uptime = millis();
|
||||
unsigned long seconds = uptime / 1000;
|
||||
unsigned long minutes = seconds / 60;
|
||||
unsigned long hours = minutes / 60;
|
||||
unsigned long days = hours / 24;
|
||||
unsigned long years = days / 365;
|
||||
seconds %= 60;
|
||||
minutes %= 60;
|
||||
hours %= 24;
|
||||
days %= 365;
|
||||
|
||||
String timeString = String(years) + "-" + String(days) + "-" + String(hours) + ":" + String(minutes) + ":" + String(seconds);
|
||||
write_data = timeString + ":" + write_data;
|
||||
|
||||
File file;
|
||||
file = SD_MMC.open(path,"ab+");
|
||||
file.println(write_data);
|
||||
|
312
src/main.cpp
312
src/main.cpp
@ -1,7 +1,6 @@
|
||||
#include"Define.h"
|
||||
#include <GSMMannager.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <ArduinoHttpClient.h>
|
||||
|
||||
#include<driver/periph_ctrl.h>
|
||||
#include "SensorOptoSky.h"
|
||||
#include <SoftwareSerial.h>
|
||||
@ -12,7 +11,9 @@
|
||||
//#include "HttpsOTAUpdate.h"
|
||||
#include "slave.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "Myhttpserver.h"
|
||||
#define beePin 39
|
||||
#define BeeChain 0
|
||||
#include <wifidebug.h>
|
||||
|
||||
#define LOGGING
|
||||
@ -22,11 +23,12 @@
|
||||
int hassend = 0;
|
||||
GSMMannger *gsmmanger;
|
||||
UpDateClassByme *ProgrameUper;
|
||||
HttpClient *http;
|
||||
bool ishttpbusy = false;
|
||||
|
||||
|
||||
SensorOptoSky IS1Sensor;
|
||||
myHttpServer *httpserver;
|
||||
// SoftwareSerial myPort(MYPORT_RX, MYPORT_TX, false);
|
||||
// HardwareSerial myPort(1);
|
||||
HardwareSerial myPort(4);
|
||||
// swSer(14, 12, false, 256);
|
||||
// u_char a[]={0x01,0x04,0x00,0x00,0x00,0x06,0x70,0x08};
|
||||
u_char ret[17];
|
||||
@ -35,182 +37,7 @@ Ticker ticker;
|
||||
slave myslave;
|
||||
String log_path;
|
||||
String log_data;
|
||||
|
||||
|
||||
String getnetData()
|
||||
{
|
||||
write_log(log_path,100,"http->get11111");
|
||||
int err = http->get("/weather/php/Date.php");
|
||||
if (err != 0)
|
||||
{
|
||||
SerialMon.println(F("Date failed to connect"));
|
||||
// delay(10000);
|
||||
vTaskDelay(10000);
|
||||
return "";
|
||||
}
|
||||
write_log(log_path,100,"http->responseStatusCode222");
|
||||
int status = http->responseStatusCode();
|
||||
if (!status)
|
||||
{
|
||||
vTaskDelay(10000);
|
||||
return "";
|
||||
}
|
||||
|
||||
// SerialMon.println(F("Response Headers:"));
|
||||
write_log(log_path,100,"http->headerAvailable333");
|
||||
int times_try = 0;
|
||||
while (http->headerAvailable())
|
||||
{
|
||||
|
||||
if(times_try > 100)
|
||||
{
|
||||
write_log(log_path,100,"http->headerAvailable failed ...");
|
||||
return "-1";
|
||||
}
|
||||
write_log(log_path,100,"http->readHeaderName");
|
||||
String headerName = http->readHeaderName();
|
||||
write_log(log_path,100,"http->readHeaderValue");
|
||||
String headerValue = http->readHeaderValue();
|
||||
write_log(log_path,100,String(times_try)+"http->headerName "+headerName);
|
||||
write_log(log_path,100,String(times_try)+"http->headerValue "+headerValue);
|
||||
// SerialMon.println("Date: " + headerName + " : " + headerValue);
|
||||
vTaskDelay(100);
|
||||
times_try++;
|
||||
}
|
||||
write_log(log_path,100,"http->isResponseChunked4444");
|
||||
if (http->isResponseChunked())
|
||||
{
|
||||
// SerialMon.println(F("Date The response is chunked"));
|
||||
}
|
||||
write_log(log_path,100,"http->responseBody555");
|
||||
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);
|
||||
}
|
||||
bool IsNetOK = false;
|
||||
String fenge(String str, String fen, int index)
|
||||
{
|
||||
int weizhi;
|
||||
@ -236,19 +63,24 @@ String fenge(String str, String fen, int index)
|
||||
return "-1";
|
||||
return temps[index];
|
||||
}
|
||||
void Reuploaddata(void *) //重新上传数据
|
||||
void beebee(int timemill)
|
||||
{
|
||||
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");
|
||||
ledcAttachPin(beePin, BeeChain);
|
||||
ledcWrite(BeeChain, 125);
|
||||
vTaskDelay(timemill);
|
||||
|
||||
ledcWrite(BeeChain, 0);
|
||||
vTaskDelay(timemill);
|
||||
|
||||
ledcWrite(BeeChain, 125);
|
||||
vTaskDelay(timemill);
|
||||
|
||||
ledcWrite(BeeChain, 0);
|
||||
ledcDetachPin(beePin);
|
||||
}
|
||||
|
||||
|
||||
|
||||
String Datenow="";
|
||||
void printbytcp(String str)
|
||||
{
|
||||
@ -258,7 +90,7 @@ void printbytcp(String 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);
|
||||
bool flagsucc = httpserver->UpdateData("/weather/php/log.php", temp, lennn);
|
||||
vTaskDelay(3000);
|
||||
delete[] temp;
|
||||
|
||||
@ -327,9 +159,12 @@ String get_GPS(void)
|
||||
// }
|
||||
void setup()
|
||||
{
|
||||
Serial2.begin(115200);
|
||||
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("start");
|
||||
//return;
|
||||
Serial.println(Curentvsion);
|
||||
sdcard::init_sdcard();
|
||||
sdcard::testwriet();
|
||||
sdcard::Mkdir("/up");
|
||||
@ -337,23 +172,57 @@ void setup()
|
||||
sdcard::Mkdir("/other");
|
||||
sdcard::Mkdir("/gps");
|
||||
sdcard::Mkdir("/log");
|
||||
|
||||
beginWIFI();
|
||||
// sdcard::mylistDir("/",2);
|
||||
{
|
||||
}
|
||||
// pinMode(21, OUTPUT);
|
||||
// digitalWrite(21, HIGH);
|
||||
|
||||
pinMode(beePin, OUTPUT);
|
||||
ledcSetup(BeeChain, 220, 8);
|
||||
ledcAttachPin(beePin, 0);
|
||||
beebee(1000);
|
||||
|
||||
myslave.init(46,45);
|
||||
sleep(3);
|
||||
//sleep(3);
|
||||
readmeichaung();
|
||||
//原来的SIM800,改为现在的AIR780E4G模块,使用的是串口2。
|
||||
gsmmanger = new GSMMannger(2, 19, 20);
|
||||
|
||||
http = new HttpClient(*gsmmanger->client, "82.156.1.111");
|
||||
|
||||
String Date = getnetData();
|
||||
Serial.println("start GSMMannger");
|
||||
// gsmmanger = new GSMMannger(2, 19, 20);
|
||||
|
||||
|
||||
#if ARDUINO_USB_CDC_ON_BOOT
|
||||
|
||||
gsmmanger = new GSMMannger(2, 2, 3);
|
||||
#else
|
||||
gsmmanger = new GSMMannger(2, 19, 20);
|
||||
#endif
|
||||
IsNetOK = gsmmanger->setpu();
|
||||
httpserver = new myHttpServer();
|
||||
|
||||
if (IsNetOK)
|
||||
{
|
||||
Serial.println("start httpserver");
|
||||
|
||||
httpserver->setup1(*gsmmanger->client, "82.156.1.111");
|
||||
// httpserver->http1=new HttpClient(*gsmmanger->client, "82.156.1.111");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Serial.println("start httpserver"+String(httpserver->http->iServerName));
|
||||
String Date = httpserver->getnetData();
|
||||
if (Date=="error")
|
||||
{
|
||||
Serial.println("getnetData failed,esp_restart");
|
||||
esp_restart();
|
||||
/* code */
|
||||
}
|
||||
|
||||
Serial.println("date is :"+Date);
|
||||
String tem = fenge(Date," ",0);
|
||||
log_path = "/log/"+tem+".log";
|
||||
@ -388,8 +257,12 @@ void setup()
|
||||
}
|
||||
vTaskDelay(1000);
|
||||
//////////////////////////////初始化http模块//////////////////////////////////////////////
|
||||
// http = new HttpClient(*gsmmanger->client, "82.156.1.111");
|
||||
ProgrameUper = new UpDateClassByme(http);
|
||||
//http = new HttpClient(*gsmmanger->client, "82.156.1.111");
|
||||
if (IsNetOK)
|
||||
{
|
||||
ProgrameUper = new UpDateClassByme(httpserver->http1);
|
||||
}
|
||||
|
||||
|
||||
IS1Sensor.initSensor();
|
||||
String StationID = IS1Sensor.SensorInfo.serialnumber;
|
||||
@ -408,13 +281,13 @@ void setup()
|
||||
// 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);
|
||||
Serial.println(Upheader);
|
||||
httpserver->UpdateData("/weather/php/SensorInfoUp.php", (char *)Upheader.c_str(), Upheader.length());
|
||||
write_log(log_path,10,"IS1 Init ....");
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
httpserver-> http1->stop();
|
||||
ticker.attach(60 * 60, Reuploaddata2);
|
||||
write_log(log_path,10,"IS1 Init Success.");
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -469,7 +342,7 @@ void loop()
|
||||
write_log(log_path,10,"start gsmmanger->loop()");
|
||||
gsmmanger->loop();
|
||||
#ifdef DINBIAO
|
||||
String Datenow1=getnetData();
|
||||
String Datenow1= httpserver->getnetData();
|
||||
Datenow =fenge(Datenow1, " ", 0) + "_" + fenge(fenge(Datenow1, " ", 1), ":", 0) + "_" + fenge(fenge(Datenow1, " ", 1), ":", 1) + "_" + fenge(fenge(Datenow1, " ", 1), ":", 2);
|
||||
IS1Sensor.PrintFunc=printbytcp;
|
||||
#endif
|
||||
@ -481,23 +354,24 @@ void loop()
|
||||
///////////////获取时间
|
||||
////////通过GPS获取时间,如果获取失败就通过4G访问网页获取。如果获取成功那就对GPS数据进行分割解析出时间。
|
||||
String gpsbac;
|
||||
for(int i = 0 ;i < 201 ; i++)
|
||||
for(int i = 0 ;i < 5 ; i++)
|
||||
{
|
||||
write_log(log_path,10,"start getnetData()");
|
||||
Date = getnetData();
|
||||
if(Date == "-1")
|
||||
Date = httpserver->getnetData();
|
||||
if(Date == "error")
|
||||
{
|
||||
write_log(log_path,10,"start get_GPS()");
|
||||
Date = get_GPS();
|
||||
if(Date != "-1")
|
||||
{
|
||||
break;
|
||||
if(hassend == 0)
|
||||
{
|
||||
gpsbac = StationID+"#"+Date;
|
||||
int lennn = gpsbac.length();
|
||||
char *temp = new char[lennn];
|
||||
memcpy(temp, gpsbac.c_str(), gpsbac.length());
|
||||
bool flagsucc = UpdateData("/weather/php/StationGPSinfo.php", temp, lennn);
|
||||
bool flagsucc = httpserver->UpdateData("/weather/php/StationGPSinfo.php", temp, lennn);
|
||||
|
||||
if (!flagsucc)
|
||||
{
|
||||
@ -514,6 +388,10 @@ void loop()
|
||||
hassend--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// break;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
@ -563,7 +441,7 @@ void loop()
|
||||
//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);
|
||||
bool flagsucc = httpserver->UpdateData("/weather/php/SpectralDataUp.php", temp, lennn);
|
||||
vTaskDelay(3000);
|
||||
if (!flagsucc)
|
||||
{
|
||||
@ -593,7 +471,7 @@ void loop()
|
||||
// temp[Downheader.length()+i]=str[i];
|
||||
}
|
||||
memcpy(temp + Downheader.length(), IS1Sensor.DownData,IS1Sensor.SensorInfo.BandNum * 2);
|
||||
flagsucc = UpdateData("/weather/php/SpectralDataUp.php", temp, lennn);
|
||||
flagsucc = httpserver->UpdateData("/weather/php/SpectralDataUp.php", temp, lennn);
|
||||
vTaskDelay(3000);
|
||||
|
||||
if (!flagsucc)
|
||||
@ -613,7 +491,7 @@ void loop()
|
||||
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");
|
||||
flagsucc = httpserver->UpdateData("/weather/php/WindsensorUp.php", temp, lennn, "application/json");
|
||||
vTaskDelay(3000);
|
||||
if (!flagsucc)
|
||||
{
|
||||
|
@ -34,23 +34,36 @@ void slave::init(int8_t MY485PORT_RX,int8_t MY485PORT_TX){
|
||||
|
||||
// GPSSeiral.begin(115200, SWSERIAL_8N1, 2, 12, false);
|
||||
wireme.setPins(7,8);
|
||||
|
||||
wireme.begin();
|
||||
Serial.println("slave init ...");
|
||||
if (!mlx.begin(MLX90614_I2CADDR,&wireme)) {
|
||||
Serial.println("Error connecting to MLX sensor. Check wiring.");
|
||||
//while (1);
|
||||
return ;
|
||||
};
|
||||
mlx.writeEmissivity(new_emissivity); // this does the 0x0000 erase write
|
||||
isinit=true;
|
||||
|
||||
mlx.writeEmissivity(new_emissivity);
|
||||
|
||||
Serial.println(sizeof(openGNRMC));
|
||||
|
||||
|
||||
}
|
||||
|
||||
double slave::getMLX(){
|
||||
if (/* condition */!isinit)
|
||||
{
|
||||
return 0;
|
||||
/* code */
|
||||
}
|
||||
|
||||
double a =mlx.readObjectTempC();
|
||||
return a;
|
||||
// Serial.write((char*) &a,8);
|
||||
}
|
||||
|
||||
void slave::getWehter(){
|
||||
|
||||
while (my485Port->read()!=-1);
|
||||
my485Port->write(a,8);
|
||||
delay(90);
|
||||
@ -89,6 +102,7 @@ float slave::getYuliang(){
|
||||
}
|
||||
|
||||
int32_t slave::getYuliangfuliang(){
|
||||
|
||||
while (my485Port->read()!=-1);
|
||||
my485Port->write(yuliangfuliangdu,8);
|
||||
delay(90);
|
||||
@ -107,6 +121,7 @@ int32_t slave::getYuliangfuliang(){
|
||||
|
||||
/// 返回1,表示ok
|
||||
uint8_t slave::claeryuliang(){
|
||||
|
||||
while (my485Port->read()!=-1);
|
||||
my485Port->write(ClearYL,8);
|
||||
delay(90);
|
||||
|
@ -22,6 +22,7 @@ class slave
|
||||
float getYuliang();
|
||||
int32_t getYuliangfuliang();
|
||||
uint8_t claeryuliang();
|
||||
bool isinit = false;
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user