V2.1
This commit is contained in:
@ -25,14 +25,14 @@ struct IS11_datastruct
|
||||
{
|
||||
u_int8_t type = 0; // 0 DN 1 Radiance 2 重采样 3 Reflectance 4 gain 5 offset 6 fanshelv
|
||||
u_int8_t direction = 0; //0 up 1 down 2 dark_up 3 dark_down
|
||||
u_int8_t tuigan_stat =0;//0:伸 1:缩
|
||||
u_int8_t tuigan_stat = 0;//0:伸 1:缩
|
||||
u_int8_t year= 0;
|
||||
u_int8_t month= 0;
|
||||
u_int8_t day= 0;
|
||||
u_int8_t hour= 0;
|
||||
u_int8_t minute= 0;
|
||||
u_int8_t second= 0;
|
||||
u_int8_t NCa = 0; //手动对齐,方便解析。
|
||||
u_int8_t NCa = 0; //手动对齐,方便解 析。
|
||||
u_int8_t NCb = 0;
|
||||
u_int8_t NCc = 0;
|
||||
u_int32_t shutter_time = 0;
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
#include "GSMMannager.h"
|
||||
// #include "SoftwareSerial.h"
|
||||
// uint32_t AIR_AutoBaud();
|
||||
|
||||
|
||||
const char apn[] = "CMNET";
|
||||
const char gprsUser[] = "";
|
||||
@ -11,94 +10,63 @@ GSMMannger::GSMMannger(int serialnumber, int rx, int tx)
|
||||
{
|
||||
pinMode(37, OUTPUT); //pin32控制sim800C电源 高电平上电 低电平断电
|
||||
digitalWrite(37, HIGH);
|
||||
vTaskDelay(1000*10);
|
||||
vTaskDelay(2000);
|
||||
// delay(1000*10);
|
||||
// digitalWrite(37, LOW);
|
||||
|
||||
MySerial=new HardwareSerial(serialnumber);
|
||||
|
||||
MySerial->setTxBufferSize(1024*10);
|
||||
modem = new TinyGsm(*MySerial);
|
||||
MySerial->begin(115200, SERIAL_8N1, rx, tx);
|
||||
client = new TinyGsmClient(*modem);
|
||||
// !!!!!!!!!!! <20>ϵ<EFBFBD>
|
||||
// Serial.println("Wait...");
|
||||
write_log(log_path,"Wait...",10);
|
||||
|
||||
// Serial.println("Wait...1");
|
||||
write_log(log_path,"Wait...1",10);
|
||||
vTaskDelay(1800);
|
||||
// Set your reset, enable, power pins here
|
||||
// !!!!!!!!!!!
|
||||
|
||||
vTaskDelay(5000);
|
||||
// Set GSM module baud rate
|
||||
// MySerial->readString();
|
||||
int banddd=TinyGsmAutoBaud(*MySerial, rx, tx, 9600,460800);
|
||||
// delay(5000);
|
||||
|
||||
int banddd= TinyGsmAutoBaud(*MySerial, 9600,460800);
|
||||
if (banddd==0)
|
||||
{
|
||||
// Serial.println("fail to connect sim800 reboot");
|
||||
write_log(log_path,"fail to connect sim800 reboot",10);
|
||||
esp_restart();
|
||||
/* code */
|
||||
}
|
||||
|
||||
// Serial.println("band is" + String(banddd));
|
||||
write_log(log_path,"band is" + String(banddd),10);
|
||||
vTaskDelay(6000);
|
||||
|
||||
// delay(6000);
|
||||
modem->init();
|
||||
|
||||
String modemInfo = modem->getModemInfo();
|
||||
if (modemInfo=="")
|
||||
{
|
||||
// Serial.println("fail to getmode reboot");
|
||||
write_log(log_path,"fail to getmode reboot",10);
|
||||
|
||||
esp_restart();
|
||||
/* code */
|
||||
}
|
||||
// Serial.print("Modem Info: ");
|
||||
write_log(log_path,"Modem Info: ",10);
|
||||
|
||||
//以后用4G再
|
||||
// SerialMon.println(modemInfo);
|
||||
write_log(log_path,modemInfo,10);
|
||||
if (GSM_PIN && modem->getSimStatus() != 3)
|
||||
{
|
||||
modem->simUnlock(GSM_PIN);
|
||||
}
|
||||
// SerialMon.print("Waiting for network...");
|
||||
write_log(log_path,"Waiting for network...",10);
|
||||
if (!modem->waitForNetwork())
|
||||
{
|
||||
// SerialMon.println(" fail");
|
||||
write_log(log_path,"fail",10);
|
||||
vTaskDelay(10000);
|
||||
|
||||
// delay(10000);
|
||||
return;
|
||||
}
|
||||
// SerialMon.println(" success");
|
||||
write_log(log_path,"success",10);
|
||||
|
||||
if (modem->isNetworkConnected())
|
||||
{
|
||||
// SerialMon.println("Network connected");
|
||||
write_log(log_path,"Network connected",10);
|
||||
|
||||
}
|
||||
// SerialMon.print(F("Connecting to "));
|
||||
write_log(log_path,"Connecting to ",10);
|
||||
// SerialMon.print(apn);
|
||||
write_log(log_path,apn,10);
|
||||
|
||||
if (!modem->gprsConnect(apn, gprsUser, gprsPass))
|
||||
{
|
||||
// SerialMon.println(" fail");
|
||||
write_log(log_path,"fail",10);
|
||||
vTaskDelay(10000);
|
||||
|
||||
// delay(10000);
|
||||
return;
|
||||
}
|
||||
// SerialMon.println(" success");
|
||||
write_log(log_path,"success",10);
|
||||
|
||||
if (modem->isGprsConnected())
|
||||
{
|
||||
// SerialMon.println("GPRS connected");
|
||||
write_log(log_path,"GPRS connected",10);
|
||||
|
||||
}
|
||||
modem->NTPServerSync();
|
||||
}
|
||||
@ -135,7 +103,8 @@ void GSMMannger::loop()
|
||||
{
|
||||
SerialMon.println(" re wait For Network fail");
|
||||
esp_restart();
|
||||
vTaskDelay(10000);
|
||||
// delay(10000);
|
||||
// vTaskDelay(1000);
|
||||
return;
|
||||
}
|
||||
if (modem->isNetworkConnected())
|
||||
@ -153,7 +122,8 @@ void GSMMannger::loop()
|
||||
{
|
||||
SerialMon.println(" set apn gprsuser gprspass fail");
|
||||
esp_restart();
|
||||
vTaskDelay(10000);
|
||||
// delay(10000);
|
||||
// vTaskDelay(1000);
|
||||
return;
|
||||
}
|
||||
if (modem->isGprsConnected())
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
// #define TINY_GSM_MODEM_SIM800
|
||||
#define TINY_GSM_MODEM_BG96
|
||||
#define SerialMon Serial
|
||||
#define SerialMon Serial0
|
||||
#include <TinyGsmClient.h>
|
||||
#include <PubSubClient.h>
|
||||
#include "log.h"
|
||||
@ -23,16 +23,16 @@
|
||||
class GSMMannger
|
||||
{
|
||||
public:
|
||||
GSMMannger(int serialnumber,int rx,int tx); // <20><><EFBFBD>ǹ<EFBFBD><C7B9>캯<EFBFBD><ECBAAF>
|
||||
// GSMMannger();
|
||||
TinyGsm *modem;
|
||||
TinyGsmClient *client;
|
||||
String GetDataAndTime();
|
||||
void loop();
|
||||
String I2toS(int n);
|
||||
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;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,10 +1,20 @@
|
||||
#include"SDmanger.h"
|
||||
#define sd_cmd 10
|
||||
#define sd_clk 9
|
||||
#define sd_dat0 11
|
||||
#define sd_dat1 12
|
||||
#define sd_dat2 13
|
||||
#define sd_dat3 14
|
||||
|
||||
|
||||
File Comenfile;
|
||||
|
||||
int sdcard::init_sdcard()
|
||||
{
|
||||
SD_MMC.setPins(9,10,11,12,13,14);
|
||||
int succ = SD_MMC.begin("/sdcard", true,true,20000);
|
||||
|
||||
SD_MMC.setPins(sd_clk,sd_cmd,sd_dat0,sd_dat1,sd_dat2,sd_dat3);
|
||||
// int succ = SD_MMC.begin("/sdcard", true,true,20000);
|
||||
int succ = SD_MMC.begin("/sdcard", false, false,40000,5);
|
||||
if (succ) {
|
||||
// Serial.printf("SD_MMC Begin: %d\n", succ);
|
||||
write_log(log_path,"SD_MMC Begin: "+String(succ),10);
|
||||
|
||||
@ -8,8 +8,7 @@ struct IS11_datastruct IS11_datastruct_fanshelv;
|
||||
STRSensorInfo SensorIS11::initSensor()
|
||||
{
|
||||
// IS1Sensor.SetPortName(id);
|
||||
pinMode(5,OUTPUT);
|
||||
pinMode(6,OUTPUT);
|
||||
|
||||
radiance_struct_up.shutter = 1;
|
||||
radiance_struct_down.shutter = 1;
|
||||
|
||||
@ -24,10 +23,9 @@ STRSensorInfo SensorIS11::initSensor()
|
||||
SensorInfo.maxValue = 65535;
|
||||
uint8_t buff[4];
|
||||
String path2 = "/system/index.bin";
|
||||
File file;
|
||||
File file;
|
||||
if(SD_MMC.exists(path2))
|
||||
{
|
||||
|
||||
file = SD_MMC.open(path2,"rb");
|
||||
file.read(buff,4);
|
||||
file.flush();
|
||||
@ -138,13 +136,18 @@ STRSensorInfo SensorIS11::GetSensorInfo()
|
||||
void SensorIS11::SetShutter(int id)
|
||||
{
|
||||
switch (id) {
|
||||
case 1:{ //关
|
||||
digitalWrite(5,LOW);
|
||||
case 1:
|
||||
{ //关
|
||||
// digitalWrite(5,LOW);
|
||||
|
||||
shutter_off();
|
||||
vTaskDelay(200);
|
||||
break;
|
||||
}
|
||||
case 2:{ //开
|
||||
digitalWrite(5,HIGH);
|
||||
case 2:
|
||||
{ //开
|
||||
// digitalWrite(5,HIGH);
|
||||
shutter_up();
|
||||
vTaskDelay(200);
|
||||
break;
|
||||
}
|
||||
@ -158,15 +161,19 @@ void SensorIS11::servo_direction(int direction)
|
||||
switch (direction)
|
||||
{
|
||||
case 0:{
|
||||
// servo_set_angle(12);
|
||||
|
||||
|
||||
shutter_down();
|
||||
servo_down();
|
||||
vTaskDelay(1500);
|
||||
vTaskDelay(500);
|
||||
shutter_off();
|
||||
break;
|
||||
}
|
||||
case 1:{
|
||||
// servo_set_angle(200);
|
||||
shutter_up();
|
||||
servo_up();
|
||||
vTaskDelay(1500);
|
||||
vTaskDelay(500);
|
||||
shutter_off();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,6 +14,12 @@
|
||||
#include "InterpolationLib.h"
|
||||
#include "CastumullSpline.h"
|
||||
|
||||
extern struct IS11_datastruct IS11_datastruct_fanshelv;
|
||||
extern struct IS11_datastruct IS11_datastruct_up;
|
||||
extern struct IS11_datastruct IS11_datastruct_down;
|
||||
extern struct IS11_datastruct IS11_datastruct_dark_up;
|
||||
extern struct IS11_datastruct IS11_datastruct_dark_down;
|
||||
|
||||
class SensorIS11 {
|
||||
public:
|
||||
SensorIS11();
|
||||
@ -45,7 +51,7 @@ public:
|
||||
|
||||
void advanced_mode(u_int32_t direction,u_int32_t shutter_time,u_int32_t collect_times,u_int32_t remove_dark);
|
||||
void opt(u_int32_t direction);
|
||||
PRINTFUNC PrintFunc;
|
||||
// PRINTFUNC PrintFunc;
|
||||
void send_chongcaiyang(HardwareSerial *wb485Serial,IS11_datastruct *IS11_datastructure,uint32_t fengbao_num);
|
||||
|
||||
|
||||
|
||||
@ -28,6 +28,9 @@ bool fenge(String &zifuchuan, String &outstring, String fengefu)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
TCPserver::TCPserver(int port)
|
||||
{
|
||||
server = new WiFiServer(port);
|
||||
@ -123,20 +126,17 @@ void TCPserver::loop()
|
||||
/* 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())
|
||||
|
||||
@ -4,7 +4,8 @@
|
||||
|
||||
void adc_init()
|
||||
{
|
||||
pinMode(ADC_PIN,INPUT);
|
||||
pinMode(ADC_PIN,ANALOG);
|
||||
analogReadResolution(12);
|
||||
}
|
||||
|
||||
float adc_read()
|
||||
@ -19,4 +20,6 @@ float adc_read()
|
||||
power = power / 10.f + 0.51;
|
||||
// write_log(log_path,"power: " + String(power),10);
|
||||
return power;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
#define ADC_H
|
||||
#include <Arduino.h>
|
||||
#include "log.h"
|
||||
#define ADC_PIN 35
|
||||
#define ADC_PIN 1
|
||||
void adc_init();
|
||||
float adc_read();
|
||||
|
||||
|
||||
18
src/beep.cpp
18
src/beep.cpp
@ -6,20 +6,26 @@ void beep_init(uint8_t beep_chan, uint32_t beep_freq, uint8_t beep_bit_num)
|
||||
{
|
||||
chan = beep_chan;
|
||||
bit_num = beep_bit_num;
|
||||
ledcSetup(chan, beep_freq , bit_num);
|
||||
ledcAttachPin(BEEP_PIN, chan);
|
||||
ledcWrite(chan, 0);
|
||||
// ledcSetup(chan, beep_freq , bit_num);
|
||||
// ledcAttachPin(BEEP_PIN, chan);
|
||||
// ledcWrite(chan, 0);
|
||||
ledcAttachChannel(BEEP_PIN,beep_freq,bit_num,6);
|
||||
// ledcAttach(BEEP_PIN,beep_freq,bit_num);
|
||||
ledcWrite(BEEP_PIN, 0); // 写入 PWM 占空比
|
||||
}
|
||||
|
||||
void beep_run( uint32_t freq,uint32_t duty)
|
||||
{
|
||||
ledcSetup(chan, freq , bit_num);
|
||||
// ledcSetup(chan, freq , bit_num);
|
||||
// ledcWrite(chan, duty);
|
||||
|
||||
ledcAttach(BEEP_PIN,freq,bit_num);
|
||||
ledcWrite(BEEP_PIN, duty); // 写入 PWM 占空比
|
||||
|
||||
ledcWrite(chan, duty);
|
||||
}
|
||||
void beep_stop()
|
||||
{
|
||||
ledcWrite(chan, 0);
|
||||
ledcWrite(BEEP_PIN, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
15
src/comon.h
15
src/comon.h
@ -1,18 +1,5 @@
|
||||
#include<Arduino.h>
|
||||
|
||||
// struct STRSensorInfo
|
||||
// {
|
||||
// std::string SensorName;
|
||||
// long maxValue;
|
||||
// long BandNum;
|
||||
// std::string WavelenthStr;
|
||||
// float *wavelenthlist;
|
||||
// //double *wavelenth;
|
||||
// bool isSensorInit;
|
||||
// std::string serialnumber;
|
||||
// float a1,a2,a3,a4;
|
||||
|
||||
// };
|
||||
|
||||
struct STRSensorInfo
|
||||
{
|
||||
@ -29,6 +16,6 @@ struct STRSensorInfo
|
||||
};
|
||||
|
||||
|
||||
typedef void (*PRINTFUNC)(std::string );
|
||||
// typedef void (*PRINTFUNC)(std::string );
|
||||
|
||||
|
||||
|
||||
@ -4,60 +4,5 @@
|
||||
"path": ".."
|
||||
}
|
||||
],
|
||||
"settings": {
|
||||
"files.associations": {
|
||||
"*.tpp": "cpp",
|
||||
"sstream": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"array": "cpp",
|
||||
"deque": "cpp",
|
||||
"string": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"unordered_set": "cpp",
|
||||
"vector": "cpp",
|
||||
"string_view": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"fstream": "cpp",
|
||||
"utility": "cpp",
|
||||
"ostream": "cpp",
|
||||
"random": "cpp",
|
||||
"atomic": "cpp",
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"map": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"new": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"ratio": "cpp",
|
||||
"thread": "cpp",
|
||||
"chrono": "cpp"
|
||||
}
|
||||
}
|
||||
"settings": {}
|
||||
}
|
||||
341
src/gsmm_http.cpp
Normal file
341
src/gsmm_http.cpp
Normal file
@ -0,0 +1,341 @@
|
||||
#include "gsmm_http.h"
|
||||
// #define SerialAT Serial2 // 使用 UART1 连接 4G 模块
|
||||
|
||||
// void sendAT(String cmd, uint16_t delayMs = 500) {
|
||||
// SerialAT.println(cmd);
|
||||
// vTaskDelay(delayMs);
|
||||
// while (SerialAT.available()) {
|
||||
// Serial0.write(SerialAT.read()); // 打印模块返回
|
||||
// }
|
||||
// }
|
||||
|
||||
// void httpUpload(float temp, float hum)
|
||||
// {
|
||||
// sendAT("AT+HTTPINIT");
|
||||
// sendAT("AT+HTTPPARA=\"CID\",1");
|
||||
// sendAT("AT+HTTPPARA=\"URL\",\"http://tower.iris-rs.cn/HyperspectralV2/DataUpload.php\"");
|
||||
|
||||
// String json = "{\"temperature\":" + String(temp) + ",\"humidity\":" + String(hum) + "}";
|
||||
// sendAT("AT+HTTPDATA=" + String(json.length()) + ",10000");
|
||||
// SerialAT.print(json);
|
||||
// SerialAT.write(0x1A);
|
||||
// vTaskDelay(2000);
|
||||
|
||||
// sendAT("AT+HTTPACTION=1"); // 1 = POST
|
||||
// vTaskDelay(3000);
|
||||
// sendAT("AT+HTTPREAD");
|
||||
// sendAT("AT+HTTPTERM");
|
||||
// }
|
||||
|
||||
// HttpClient *http;
|
||||
// // #ifdef GPS_4G
|
||||
// // //初始化AIR780EG
|
||||
// // http_gsmmanger = new GSMMannger(SIMUARTNUMER, SIMUART_RX, SIMUART_TX);
|
||||
// // http = new HttpClient(*http_gsmmanger->client, "tower.iris-rs.cn");
|
||||
|
||||
// // String Date = getnetData();
|
||||
// // write_log(log_path,"date is :"+Date,10);
|
||||
|
||||
// // gps_struct gps_structure;
|
||||
|
||||
// // String gpsbac = get_GPS(&gps_structure);
|
||||
|
||||
// // if (gpsbac != "-1")
|
||||
// // {
|
||||
// // // calcSunriseSunset(now.year+2000, now.month, now.day,gps_structure.latitude, gps_structure.longitude, transit, sunrise, sunset);
|
||||
// // }
|
||||
// // else
|
||||
// // {
|
||||
// // write_log(log_path,"no gps",10);
|
||||
// // }
|
||||
// // #endif
|
||||
|
||||
|
||||
|
||||
// GSMMannger *http_gsmmanger;
|
||||
// void gsmm_http_init()
|
||||
// {
|
||||
// http_gsmmanger = new GSMMannger(SIMUARTNUMER, SIMUART_RX, SIMUART_TX);
|
||||
// http = new HttpClient(*http_gsmmanger->http_client, "tower.iris-rs.cn");
|
||||
|
||||
// String Date = getnetData();
|
||||
// write_log(log_path,"date is :"+Date,10);
|
||||
// gps_struct gps_structure;
|
||||
|
||||
// String gpsbac = get_GPS(&gps_structure);
|
||||
// }
|
||||
|
||||
// String getnetData()
|
||||
// {
|
||||
// write_log(log_path,"start get net data",10);
|
||||
// int err = http->get("/weather/php/Date.php");
|
||||
// if (err != 0)
|
||||
// {
|
||||
// return "-1";
|
||||
// }
|
||||
// write_log(log_path,"responseStatusCode",10);
|
||||
// int status = http->responseStatusCode();
|
||||
// if (!status)
|
||||
// {
|
||||
// return "-1";
|
||||
// }
|
||||
|
||||
// int times_try = 0;
|
||||
// write_log(log_path,"headerAvailable",10);
|
||||
// while (http->headerAvailable())
|
||||
// {
|
||||
// if(times_try > 100)
|
||||
// {
|
||||
// http->stop();
|
||||
// return "-1";
|
||||
// }
|
||||
// write_log(log_path,"readHeaderName",10);
|
||||
// String headerName = http->readHeaderName();
|
||||
// write_log(log_path,"readHeaderValue",10);
|
||||
// String headerValue = http->readHeaderValue();
|
||||
|
||||
// vTaskDelay(100);
|
||||
// times_try++;
|
||||
// }
|
||||
// write_log(log_path,"isResponseChunked",10);
|
||||
// if (http->isResponseChunked())
|
||||
// {
|
||||
// }
|
||||
// write_log(log_path,"contentLength",10);
|
||||
// String body = http->responseBody();
|
||||
// http->stop();
|
||||
// return body;
|
||||
// }
|
||||
|
||||
// // /////////////////////////////////上传数据/////////////////////////////////////
|
||||
// bool UpdateData(String path,uint8_t *data, size_t lenth, String Contenttype )
|
||||
// {
|
||||
// // http_flag = 1;
|
||||
// // vTaskDelay(20);
|
||||
|
||||
// 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 *)data, lenth);
|
||||
// vTaskDelay(1000);
|
||||
// Serial0.print("send date size");
|
||||
// Serial0.println(err);
|
||||
|
||||
|
||||
// int status = http->responseStatusCode();
|
||||
// int length = http->contentLength();
|
||||
// String body = http->responseBody();
|
||||
// Serial0.println("body:"+body);
|
||||
|
||||
// http->stop();
|
||||
|
||||
// vTaskDelay(10);
|
||||
// // http_flag = 0;
|
||||
|
||||
// if((err == 0 )|| (!status) || (length == 0) || (body != "ok"))
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
// 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, (uint8_t *)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, (uint8_t *)arr, size, content);
|
||||
// if (!flagsucc)
|
||||
// {
|
||||
// return;
|
||||
// /* code */
|
||||
// }
|
||||
|
||||
// delete[] arr;
|
||||
// sdcard::deleteFolderOrFile(files.at(i).c_str());
|
||||
// /* code */
|
||||
// }
|
||||
// }
|
||||
// vTaskDelay(1);
|
||||
// }
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// String get_GPS(gps_struct *gps)
|
||||
// {
|
||||
|
||||
// // write_log(log_path,"start get GPS ",10);
|
||||
// // String gpsbac,Date,temp,Latitude,Longitude;
|
||||
// // http_gsmmanger->modem->sendAT(GF("+CGNSPWR?"));
|
||||
// // http_gsmmanger->modem->waitResponse("OK");
|
||||
|
||||
// // http_gsmmanger->modem->sendAT(GF("+CGNSPWR=1"));
|
||||
// // http_gsmmanger->modem->waitResponse("OK");
|
||||
|
||||
// // http_gsmmanger->modem->sendAT(GF("+CGNSAID=31,1,1,1"));
|
||||
// // http_gsmmanger->modem->waitResponse("OK");
|
||||
|
||||
// // http_gsmmanger->modem->sendAT(GF("+CGNSINF"));
|
||||
|
||||
// // //获取gps信息
|
||||
// // http_gsmmanger->modem->waitResponse(5000,gpsbac);
|
||||
// // write_log(log_path,"gpsbac is " + gpsbac,10);
|
||||
|
||||
// // //检测是否有效
|
||||
// // temp = gpsbac.substring(16,17);
|
||||
// // // write_log(log_path,"hahaha :" + temp,10);
|
||||
|
||||
// // if(temp != "1")
|
||||
// // {
|
||||
// // // write_log(log_path,"gps error,hahahaha",10);
|
||||
// // return "-1";
|
||||
// // }
|
||||
// // //截取时间
|
||||
// // Date = gpsbac.substring(18,32);
|
||||
// // temp = Date.substring(0,4) + "-" + Date.substring(4,6) + "-" +Date.substring(6,8) + " " + Date.substring(8,10) + ":" +Date.substring(10,12) + ":" +Date.substring(12,-1);
|
||||
|
||||
// // gps->year = Date.substring(0,4).toInt();
|
||||
// // gps->month = Date.substring(4,6).toInt();
|
||||
// // gps->day = Date.substring(6,8).toInt();
|
||||
// // gps->hour = Date.substring(8,10).toInt();
|
||||
// // gps->minute = Date.substring(10,12).toInt();
|
||||
// // gps->second = Date.substring(12,-1).toInt();
|
||||
|
||||
// // Date = temp;
|
||||
// // // +CGNSINF: 1,1,20240430052525,40.040938,116.328013,51.900,0.26,0.00,3,,2.14,2.42,4.00,,10,8,,,34,,
|
||||
|
||||
// // // OK
|
||||
// // ////////获取经纬度//////////
|
||||
// // temp = gpsbac.substring(33);
|
||||
// // // write_log(log_path,"Longitude is :" + temp,10);
|
||||
// // int pos = temp.indexOf(",");
|
||||
// // Latitude = temp.substring(0,pos);
|
||||
// // gps->latitude = Latitude.toFloat();
|
||||
// // // write_log(log_path,"Latitude ::::" + Latitude,10);
|
||||
|
||||
// // temp = temp.substring(pos+1);
|
||||
// // // write_log(log_path,"Longitude is :" + temp,10);
|
||||
// // pos = temp.indexOf(",");
|
||||
// // Longitude = temp.substring(0,pos);
|
||||
// // gps->longitude = Longitude.toFloat();
|
||||
// // // write_log(log_path,"Longitude ::::" + Longitude,10);
|
||||
|
||||
// // if(Date.indexOf(",") != -1)
|
||||
// // {
|
||||
// // return "-1";
|
||||
// // }
|
||||
// // return Date;
|
||||
|
||||
// //////////////////////////////////////////////////////////////////////////////
|
||||
// String gpsbac;
|
||||
// write_log(log_path,"start get GPS ",10);
|
||||
|
||||
// http_gsmmanger->modem->sendAT(GF("+QGPS=1"));
|
||||
// http_gsmmanger->modem->waitResponse("OK");
|
||||
|
||||
// http_gsmmanger->modem->sendAT(GF("+QGPSLOC=0"));
|
||||
// // http_gsmmanger->modem->waitResponse("OK");
|
||||
|
||||
|
||||
// //获取gps信息
|
||||
// http_gsmmanger->modem->waitResponse(5000,gpsbac);
|
||||
// write_log(log_path,"gpsbac is " + gpsbac,10);
|
||||
|
||||
// // //检测是否有效
|
||||
// // temp = gpsbac.substring(16,17);
|
||||
// // // write_log(log_path,"hahaha :" + temp,10);
|
||||
|
||||
// // if(temp != "1")
|
||||
// // {
|
||||
// // // write_log(log_path,"gps error,hahahaha",10);
|
||||
// // return "-1";
|
||||
// // }
|
||||
// // //截取时间
|
||||
// // Date = gpsbac.substring(18,32);
|
||||
// // temp = Date.substring(0,4) + "-" + Date.substring(4,6) + "-" +Date.substring(6,8) + " " + Date.substring(8,10) + ":" +Date.substring(10,12) + ":" +Date.substring(12,-1);
|
||||
|
||||
// // gps->year = Date.substring(0,4).toInt();
|
||||
// // gps->month = Date.substring(4,6).toInt();
|
||||
// // gps->day = Date.substring(6,8).toInt();
|
||||
// // gps->hour = Date.substring(8,10).toInt();
|
||||
// // gps->minute = Date.substring(10,12).toInt();
|
||||
// // gps->second = Date.substring(12,-1).toInt();
|
||||
|
||||
// // Date = temp;
|
||||
// // // +CGNSINF: 1,1,20240430052525,40.040938,116.328013,51.900,0.26,0.00,3,,2.14,2.42,4.00,,10,8,,,34,,
|
||||
|
||||
// // // OK
|
||||
// // ////////获取经纬度//////////
|
||||
// // temp = gpsbac.substring(33);
|
||||
// // // write_log(log_path,"Longitude is :" + temp,10);
|
||||
// // int pos = temp.indexOf(",");
|
||||
// // Latitude = temp.substring(0,pos);
|
||||
// // gps->latitude = Latitude.toFloat();
|
||||
// // // write_log(log_path,"Latitude ::::" + Latitude,10);
|
||||
|
||||
// // temp = temp.substring(pos+1);
|
||||
// // // write_log(log_path,"Longitude is :" + temp,10);
|
||||
// // pos = temp.indexOf(",");
|
||||
// // Longitude = temp.substring(0,pos);
|
||||
// // gps->longitude = Longitude.toFloat();
|
||||
// // // write_log(log_path,"Longitude ::::" + Longitude,10);
|
||||
|
||||
// // if(Date.indexOf(",") != -1)
|
||||
// // {
|
||||
// // return "-1";
|
||||
// // }
|
||||
|
||||
// return gpsbac;
|
||||
// }
|
||||
31
src/gsmm_http.h
Normal file
31
src/gsmm_http.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef __gsmm_http__
|
||||
#define __gsmm_http__
|
||||
|
||||
|
||||
#include "head.h"
|
||||
#include "TinyGsmCommon.h"
|
||||
|
||||
// typedef struct gps_struct{
|
||||
// uint16_t year;
|
||||
// uint8_t month;
|
||||
// uint8_t day;
|
||||
// uint8_t hour;
|
||||
// uint8_t minute;
|
||||
// uint8_t second;
|
||||
// float latitude;
|
||||
// float longitude;
|
||||
// }gps_struct;
|
||||
|
||||
|
||||
// void httpUpload(float temp, float hum);
|
||||
// void gsmm_http_init();
|
||||
// String getnetData();
|
||||
// bool UpdateData(String path,uint8_t *data, size_t lenth, String Contenttype );
|
||||
// // void ReuploadData(String path, String webpath, String content = "");
|
||||
|
||||
|
||||
|
||||
// String get_GPS(gps_struct *gps);
|
||||
|
||||
|
||||
#endif
|
||||
432
src/gsmm_mqtt.cpp
Normal file
432
src/gsmm_mqtt.cpp
Normal file
@ -0,0 +1,432 @@
|
||||
#include "gsmm_mqtt.h"
|
||||
|
||||
|
||||
|
||||
GSMMannger *gsmmanger;
|
||||
PubSubClient *mqtt_client; // 修改为指针类型,避免使用未初始化的对象
|
||||
const char* mqtt_server = "tower.iris-rs.cn"; // 可替换为你自己的Broker地址
|
||||
const uint32_t mqtt_port = 40000;
|
||||
const char *mqtt_client_id = "gaoguangpu_001";
|
||||
const char *mqtt_username = "remotecontroler";
|
||||
const char *mqtt_password = "irishk";
|
||||
const char *publish_topic = "gaoguangpu/return/IS11_id";
|
||||
const char *subscribe_topic = "gaoguangpu/command/IS11_id";
|
||||
|
||||
EventGroupHandle_t http_event_group;
|
||||
|
||||
void callback(char* topic, byte* payload, unsigned int length) {
|
||||
// Serial0.print("Message arrived on topic: ");
|
||||
// Serial0.print(topic);
|
||||
// Serial0.print(". Message: ");
|
||||
// for (int i = 0; i < length; i++) {
|
||||
// Serial0.print((char)payload[i]);
|
||||
// }
|
||||
// Serial0.println();
|
||||
|
||||
uint8_t read_buff[1024 * 10];
|
||||
memcpy(read_buff,payload,length);
|
||||
uint32_t data_length = length;
|
||||
data_length = IRIS_Cut_Befor_Header(read_buff,data_length);
|
||||
if (data_length > 0)
|
||||
{
|
||||
receive_command_unpack(read_buff,length,2);
|
||||
}
|
||||
}
|
||||
|
||||
void reconnect() {
|
||||
// 重新连接MQTT
|
||||
while (!mqtt_client->connected())
|
||||
{
|
||||
// Serial0.print("Attempting MQTT connection...");
|
||||
vTaskDelay(10);
|
||||
if (mqtt_client->connect(mqtt_client_id))
|
||||
{
|
||||
// Serial0.println("connected");
|
||||
mqtt_client->subscribe(subscribe_topic);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Serial0.print("failed, rc=");
|
||||
// Serial0.print(mqtt_client->state());
|
||||
}
|
||||
// vTaskDelay(100);
|
||||
}
|
||||
}
|
||||
|
||||
void gsmm_mqtt_loop_task(void *pvParameters)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
if (!mqtt_client->connected()) {
|
||||
reconnect();
|
||||
}
|
||||
|
||||
EventBits_t uxBits = xEventGroupGetBits(http_event_group);
|
||||
if (uxBits & mqtt_stop_bit)
|
||||
{
|
||||
mqtt_client->disconnect();
|
||||
xEventGroupSetBits(http_event_group, Http_start_bit);
|
||||
xEventGroupWaitBits(http_event_group, Http_stop_bit,pdTRUE , pdFALSE, portMAX_DELAY);
|
||||
xEventGroupClearBits(http_event_group, mqtt_stop_bit);
|
||||
}
|
||||
|
||||
mqtt_client->loop();
|
||||
gsmmanger->loop();
|
||||
|
||||
vTaskDelay(10);
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// if (!mqtt_client->connected()) {
|
||||
// reconnect();
|
||||
// }
|
||||
// mqtt_client->loop();
|
||||
// gsmmanger->loop();
|
||||
// vTaskDelay(10);
|
||||
}
|
||||
}
|
||||
|
||||
HttpClient *http;
|
||||
|
||||
UpDateClassByme ggp_UpDate(http);
|
||||
void gsmm_mqtt_init()
|
||||
{
|
||||
http_event_group = xEventGroupCreate();
|
||||
// if(http_event_group == NULL)
|
||||
// {
|
||||
// Serial0.println("Failed to create event group");
|
||||
// }
|
||||
gsmmanger = new GSMMannger(SIMUARTNUMER, SIMUART_RX, SIMUART_TX);
|
||||
mqtt_client = new PubSubClient(*gsmmanger->client); // 初始化 PubSubClient;
|
||||
mqtt_client->setServer(mqtt_server, mqtt_port);
|
||||
mqtt_client->setCallback(callback);
|
||||
|
||||
// http = new HttpClient(*gsmmanger->client, "82.156.1.111");
|
||||
http = new HttpClient(*gsmmanger->client, mqtt_server);
|
||||
xTaskCreatePinnedToCore(gsmm_mqtt_loop_task, "gsmm_mqtt_loop_task",1024*3,NULL, 1, NULL, 1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void mqtt_write(uint8_t *data , uint32_t lenth)
|
||||
{
|
||||
bool messageSent = false;
|
||||
do
|
||||
{
|
||||
messageSent = mqtt_client->publish(publish_topic,data,lenth);
|
||||
if(!messageSent) vTaskDelay(1);
|
||||
} while (!messageSent);
|
||||
}
|
||||
|
||||
bool UpdateData(String path,uint8_t *data, size_t lenth, String Contenttype )
|
||||
{
|
||||
EventBits_t uxBits = xEventGroupGetBits(http_event_group);
|
||||
while (uxBits & mqtt_stop_bit)
|
||||
{
|
||||
uxBits = xEventGroupGetBits(http_event_group);
|
||||
vTaskDelay(1);
|
||||
}
|
||||
|
||||
xEventGroupSetBits(http_event_group, mqtt_stop_bit);
|
||||
xEventGroupWaitBits(http_event_group, Http_start_bit,pdTRUE, pdFALSE,portMAX_DELAY);
|
||||
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 *)data, lenth);
|
||||
uint32_t len = lenth;
|
||||
while(len)
|
||||
{
|
||||
if(len > 1024)
|
||||
{
|
||||
err = http->write((const byte *)data, 1024);
|
||||
len -= 1024;
|
||||
data += 1024;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = http->write((const byte *)data, len);
|
||||
len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
vTaskDelay(1000*5);
|
||||
Serial0.print("send date size");
|
||||
Serial0.println(err);
|
||||
|
||||
|
||||
int status = http->responseStatusCode();
|
||||
int length = http->contentLength();
|
||||
String body = http->responseBody();
|
||||
Serial0.println("body:"+body);
|
||||
|
||||
http->stop();
|
||||
|
||||
vTaskDelay(10);
|
||||
// http_flag = 0;
|
||||
xEventGroupSetBits(http_event_group, Http_stop_bit);
|
||||
|
||||
if((err == 0 )|| (!status) || (length == 0) || (body != "ok"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
String getnetData()
|
||||
{
|
||||
EventBits_t uxBits = xEventGroupGetBits(http_event_group);
|
||||
while (uxBits & mqtt_stop_bit)
|
||||
{
|
||||
uxBits = xEventGroupGetBits(http_event_group);
|
||||
vTaskDelay(1);
|
||||
}
|
||||
xEventGroupSetBits(http_event_group, mqtt_stop_bit);
|
||||
xEventGroupWaitBits(http_event_group, Http_start_bit,pdTRUE, pdFALSE,portMAX_DELAY);
|
||||
|
||||
// write_log(log_path,"start get net data",10);
|
||||
int err = http->get("/weather/php/Date.php");
|
||||
if (err != 0)
|
||||
{
|
||||
return "-1";
|
||||
}
|
||||
// write_log(log_path,"responseStatusCode",10);
|
||||
int status = http->responseStatusCode();
|
||||
if (!status)
|
||||
{
|
||||
return "-1";
|
||||
}
|
||||
|
||||
int times_try = 0;
|
||||
// write_log(log_path,"headerAvailable",10);
|
||||
while (http->headerAvailable())
|
||||
{
|
||||
if(times_try > 100)
|
||||
{
|
||||
http->stop();
|
||||
vTaskDelay(10);
|
||||
xEventGroupSetBits(http_event_group, Http_stop_bit);
|
||||
return "-1";
|
||||
}
|
||||
// write_log(log_path,"readHeaderName",10);
|
||||
String headerName = http->readHeaderName();
|
||||
// write_log(log_path,"readHeaderValue",10);
|
||||
String headerValue = http->readHeaderValue();
|
||||
|
||||
vTaskDelay(100);
|
||||
times_try++;
|
||||
}
|
||||
// write_log(log_path,"isResponseChunked",10);
|
||||
if (http->isResponseChunked())
|
||||
{
|
||||
}
|
||||
// write_log(log_path,"contentLength",10);
|
||||
String body = http->responseBody();
|
||||
http->stop();
|
||||
vTaskDelay(10);
|
||||
xEventGroupSetBits(http_event_group, Http_stop_bit);
|
||||
return body;
|
||||
}
|
||||
String get_GPS(gps_struct *gps_info)
|
||||
{
|
||||
EventBits_t uxBits = xEventGroupGetBits(http_event_group);
|
||||
while (uxBits & mqtt_stop_bit)
|
||||
{
|
||||
uxBits = xEventGroupGetBits(http_event_group);
|
||||
vTaskDelay(1);
|
||||
}
|
||||
xEventGroupSetBits(http_event_group, mqtt_stop_bit);
|
||||
xEventGroupWaitBits(http_event_group, Http_start_bit,pdTRUE, pdFALSE,portMAX_DELAY);
|
||||
String gpsbac;
|
||||
write_log(log_path,"start get GPS ",10);
|
||||
|
||||
gsmmanger->modem->sendAT(GF("+QGPS=1"));
|
||||
gsmmanger->modem->waitResponse("OK");
|
||||
|
||||
gsmmanger->modem->sendAT(GF("+QGPSLOC=0"));
|
||||
|
||||
//获取gps信息
|
||||
gsmmanger->modem->waitResponse(5000,gpsbac);
|
||||
write_log(log_path,"gpsbac is " + gpsbac,10);
|
||||
|
||||
xEventGroupSetBits(http_event_group, Http_stop_bit);
|
||||
|
||||
if(gpsbac.indexOf("+QGPSLOC:") != -1)
|
||||
{
|
||||
return "-1";
|
||||
}
|
||||
|
||||
const char* gps_data = gpsbac.c_str();
|
||||
// 提取时间 (063416.40 -> 06:34:16.40)
|
||||
sscanf(gps_data, "%2hhd%2hhd%2hhd", &gps_info->hour, &gps_info->minute, &gps_info->second);
|
||||
|
||||
// 提取日期 (110620 -> 2020-11-06)
|
||||
sscanf(gps_data + 36, "%2hd%2hhd%2hhd", &gps_info->year, &gps_info->month, &gps_info->day);
|
||||
|
||||
// 提取纬度 (3143.2951N -> 31.721585)
|
||||
int lat_deg = gps_data[8] - '0'; // 获取纬度的度数 31
|
||||
int lat_min = gps_data[9] - '0'; // 获取纬度的分钟数 43
|
||||
float lat_min_decimal = atof(&gps_data[10]); // 获取纬度的小数部分 2951
|
||||
gps_info->latitude = lat_deg + (lat_min + lat_min_decimal / 10000) / 60.0;
|
||||
|
||||
// 提取经度 (11713.0655E -> 117.217758)
|
||||
int lon_deg = gps_data[14] - '0'; // 获取经度的度数 117
|
||||
int lon_min = gps_data[15] - '0'; // 获取经度的分钟数 13
|
||||
float lon_min_decimal = atof(&gps_data[16]); // 获取经度的小数部分 0655
|
||||
gps_info->longitude = lon_deg + (lon_min + lon_min_decimal / 10000) / 60.0;
|
||||
|
||||
return gpsbac;
|
||||
}
|
||||
|
||||
void Update_firmware(Stream &updateSource, size_t updateSize)
|
||||
{
|
||||
if (Update.begin(updateSize))
|
||||
{
|
||||
Serial0.println("Writes : ");
|
||||
size_t written = Update.writeStream(updateSource);
|
||||
if (written == updateSize)
|
||||
{
|
||||
Serial0.println("Writes : " + String(written) + " successfully");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial0.println("Written only : " + String(written) + "/" + String(updateSize) + ". Retry?");
|
||||
}
|
||||
|
||||
if (Update.end())
|
||||
{
|
||||
Serial0.println("OTA finished!");
|
||||
if (Update.isFinished())
|
||||
{
|
||||
Serial0.println("Restart ESP device!");
|
||||
abort();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial0.println("OTA not fiished");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial0.println("Error occured #: " + String(Update.getError()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial0.println("Cannot beggin update");
|
||||
}
|
||||
}
|
||||
size_t http_download(String url)
|
||||
{
|
||||
// String url="/gaoguangpu/firmware/esp32/firmware_"+version+".bin";
|
||||
int err = http->get(url.c_str());
|
||||
if (err != 0)
|
||||
{
|
||||
Serial0.println(F("Date failed to connect"));
|
||||
vTaskDelay(10000);
|
||||
return 0;
|
||||
}
|
||||
int status = http->responseStatusCode();
|
||||
if (!status)
|
||||
{
|
||||
vTaskDelay(10000);
|
||||
return 0;
|
||||
}
|
||||
Serial0.print(F("Response status code: "));
|
||||
Serial0.println(status);
|
||||
// Serial0Mon.println(F("Response Headers:"));
|
||||
size_t count=0;
|
||||
while (http->headerAvailable())
|
||||
{
|
||||
String headerName = http->readHeaderName();
|
||||
String headerValue = http->readHeaderValue();
|
||||
Serial0.println("Date: " + headerName + " : " + headerValue);
|
||||
if (headerName=="Content-Length")
|
||||
{
|
||||
count=headerValue.toInt();
|
||||
/* code */
|
||||
}
|
||||
}
|
||||
Serial0.println("lenth is "+String(count));
|
||||
if (http->isResponseChunked())
|
||||
{
|
||||
Serial0.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);
|
||||
Serial0.print("download ");
|
||||
Serial0.println(String(i*100/lent));
|
||||
/* code */
|
||||
}
|
||||
http->readBytes(str,count%1000);
|
||||
file.write((const byte *)str,count%1000);
|
||||
file.flush();
|
||||
file.close();
|
||||
|
||||
http->stop();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
bool check_file_ota(String MD5)
|
||||
{
|
||||
MD5Builder md5my;
|
||||
|
||||
File file;
|
||||
file = SD_MMC.open("/update.bin", "rb");
|
||||
size_t countdownload1 = file.size();
|
||||
md5my.begin();
|
||||
md5my.addStream(file,countdownload1);
|
||||
md5my.calculate();
|
||||
String md5com=md5my.toString();
|
||||
Serial0.println("md5 comput is:"+md5my.toString());
|
||||
Serial0.println("md5 should is:"+MD5);
|
||||
file.close();
|
||||
if (MD5 == md5com)
|
||||
{
|
||||
file = SD_MMC.open("/update.bin", "rb");
|
||||
Update_firmware(file,countdownload1);
|
||||
return true;
|
||||
/* code */
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial0.println("md5 error");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void http_OTA(String url,String MD5)
|
||||
{
|
||||
|
||||
EventBits_t uxBits = xEventGroupGetBits(http_event_group);
|
||||
while (uxBits & mqtt_stop_bit)
|
||||
{
|
||||
uxBits = xEventGroupGetBits(http_event_group);
|
||||
vTaskDelay(1);
|
||||
}
|
||||
|
||||
xEventGroupSetBits(http_event_group, mqtt_stop_bit);
|
||||
xEventGroupWaitBits(http_event_group, Http_start_bit,pdTRUE, pdFALSE,portMAX_DELAY);
|
||||
uint32_t count = http_download(url);
|
||||
if(count != 0) check_file_ota(MD5);
|
||||
|
||||
xEventGroupSetBits(http_event_group, Http_stop_bit);
|
||||
}
|
||||
|
||||
36
src/gsmm_mqtt.h
Normal file
36
src/gsmm_mqtt.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef MYMQTT_H
|
||||
#define MYMQTT_H
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "GSMMannager.h"
|
||||
#include <ArduinoOTA.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <ArduinoHttpClient.h>
|
||||
#include "head.h"
|
||||
#include <esp_ota_ops.h>
|
||||
|
||||
#define mqtt_stop_bit (1 << 0)
|
||||
#define Http_start_bit (1 << 1)
|
||||
#define Http_stop_bit (1 << 2)
|
||||
|
||||
|
||||
typedef struct gps_struct{
|
||||
uint16_t year;
|
||||
uint8_t month;
|
||||
uint8_t day;
|
||||
uint8_t hour;
|
||||
uint8_t minute;
|
||||
uint8_t second;
|
||||
float latitude;
|
||||
float longitude;
|
||||
}gps_struct;
|
||||
|
||||
void gsmm_mqtt_init();
|
||||
void mqtt_write(uint8_t *data , uint32_t lenth);
|
||||
bool UpdateData(String path,uint8_t *data, size_t lenth, String Contenttype);
|
||||
void httpUpload(uint8_t *data,uint32_t lenth);
|
||||
String getnetData();
|
||||
String get_GPS(gps_struct *gps);
|
||||
void http_OTA(String url,String MD5);
|
||||
#endif
|
||||
105
src/head.h
Normal file
105
src/head.h
Normal file
@ -0,0 +1,105 @@
|
||||
#ifndef __HEAD_H
|
||||
#define __HEAD_H
|
||||
|
||||
|
||||
|
||||
#include"Define.h"
|
||||
#include <GSMMannager.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <ArduinoHttpClient.h>
|
||||
#include<driver/periph_ctrl.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>
|
||||
#include <ArduinoJson.h>
|
||||
#include <Communication_Protocol.h>
|
||||
|
||||
#include "IRIS_Method.h"
|
||||
#include "DS18B20.h"
|
||||
#include "Servo.h"
|
||||
#include "jiaresi.h"
|
||||
#include <Ds1302.h>
|
||||
#include "servo.h"
|
||||
#include "SensorIS11.h"
|
||||
#include "tuigan.h"
|
||||
#include "beep.h"
|
||||
#include "My74HC595.h"
|
||||
#include "SolarCalculator.h"
|
||||
#include "adc.h"
|
||||
#include "mymsc.h"
|
||||
|
||||
#include "gsmm_mqtt.h"
|
||||
|
||||
#include"Define.h"
|
||||
#include <GSMMannager.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <ArduinoHttpClient.h>
|
||||
#include<driver/periph_ctrl.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>
|
||||
#include <ArduinoJson.h>
|
||||
#include <Communication_Protocol.h>
|
||||
|
||||
#include "IRIS_Method.h"
|
||||
#include "DS18B20.h"
|
||||
#include "Servo.h"
|
||||
#include "jiaresi.h"
|
||||
#include <Ds1302.h>
|
||||
#include "servo.h"
|
||||
#include "SensorIS11.h"
|
||||
#include "tuigan.h"
|
||||
#include "beep.h"
|
||||
#include "My74HC595.h"
|
||||
#include "SolarCalculator.h"
|
||||
#include "adc.h"
|
||||
#include "mymsc.h"
|
||||
|
||||
#include "gsmm_mqtt.h"
|
||||
#include "gsmm_http.h"
|
||||
|
||||
|
||||
#define LOGGING
|
||||
|
||||
#define IS1Serial_port 1
|
||||
#define IS1Serial_RX 18
|
||||
#define IS1Serial_TX 17
|
||||
|
||||
#define SIMUARTNUMER 2
|
||||
|
||||
#define wb485PORTNUMER 0
|
||||
|
||||
#ifdef ARDUINO_USB_CDC_ON_BOOT
|
||||
#define SIMUART_RX 2
|
||||
#define SIMUART_TX 3
|
||||
|
||||
#define wb485PORT_RX 44
|
||||
#define wb485PORT_TX 43
|
||||
|
||||
#else
|
||||
#define SIMUART_RX 16
|
||||
#define SIMUART_TX 17
|
||||
|
||||
#define wb485PORT_RX 2
|
||||
#define wb485PORT_TX 3
|
||||
#endif
|
||||
|
||||
#define OTA_BIT (1<<0)
|
||||
#define mode_4G_BIT (1<<1)
|
||||
|
||||
void receive_command_unpack(uint8_t * read_buf,uint16_t data_length,uint8_t port_type);
|
||||
#endif
|
||||
16
src/log.cpp
16
src/log.cpp
@ -37,25 +37,23 @@ ab+ 读写打开一个二进制文件,允许读或在文件末追加数据。
|
||||
#ifdef ARDUINO_USB_CDC_ON_BOOT
|
||||
#define U0_Serial Serial
|
||||
#else
|
||||
SoftwareSerial U0_Serial(19,20,false);
|
||||
SoftwareSerial U0_Serial(19,20,false);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
void log_init()
|
||||
{
|
||||
U0_Serial.begin(115200);
|
||||
// U0_Serial.begin(115200);
|
||||
}
|
||||
|
||||
void write_log(String path,String write_data,unsigned char level)
|
||||
{
|
||||
if(level <15) {
|
||||
U0_Serial.println(write_data);
|
||||
if(level <150) {
|
||||
// U0_Serial.println(write_data);
|
||||
Serial0.println(write_data);
|
||||
}
|
||||
if (level == 20)
|
||||
{
|
||||
U0_Serial.println(write_data);
|
||||
// U0_Serial.println(write_data);
|
||||
|
||||
File file;
|
||||
file = SD_MMC.open(path,"ab+");
|
||||
@ -67,7 +65,7 @@ void write_log(String path,String write_data,unsigned char level)
|
||||
|
||||
void write_log(uint8_t *data,uint32_t size)
|
||||
{
|
||||
U0_Serial.write(data,size);
|
||||
// U0_Serial.write(data,size);
|
||||
}
|
||||
|
||||
void save_data(String path,String write_data)
|
||||
|
||||
1593
src/main.cpp
1593
src/main.cpp
File diff suppressed because it is too large
Load Diff
@ -131,7 +131,7 @@ void my74hc595_init(){
|
||||
updatepin();
|
||||
tuigan(suo);
|
||||
|
||||
vTaskDelay(1000 * 10);
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
bool my74hc595_setpin(int index, bool val)
|
||||
{
|
||||
|
||||
123
src/mymsc.cpp
Normal file
123
src/mymsc.cpp
Normal file
@ -0,0 +1,123 @@
|
||||
// #if !SOC_USB_OTG_SUPPORTED || ARDUINO_USB_MODE
|
||||
// #error Device does not support USB_OTG or native USB CDC/JTAG is selected
|
||||
// #endif
|
||||
#include "mymsc.h"
|
||||
#include <USB.h>
|
||||
#include <USBMSC.h>
|
||||
#include <SD_MMC.h>
|
||||
|
||||
// USB Mass Storage Class (MSC) object
|
||||
USBMSC msc;
|
||||
|
||||
static void usbEventCallback(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) {
|
||||
if (event_base == ARDUINO_USB_EVENTS) {
|
||||
arduino_usb_event_data_t *data = (arduino_usb_event_data_t *)event_data;
|
||||
switch (event_id) {
|
||||
case ARDUINO_USB_STARTED_EVENT:
|
||||
// Serial.println("USB connected.");
|
||||
// 这里可以做 USB 插入时需要执行的操作
|
||||
|
||||
// setupmsc();
|
||||
break;
|
||||
case ARDUINO_USB_STOPPED_EVENT:
|
||||
// Serial.println("USB disconnected.");
|
||||
// 这里可以做 USB 拔出时需要执行的操作
|
||||
|
||||
// stopmsc();
|
||||
// esp_restart();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int32_t onWrite(uint32_t lba, uint32_t offset, uint8_t *buffer, uint32_t bufsize) {
|
||||
uint32_t secSize = SD_MMC.sectorSize();
|
||||
if (!secSize) {
|
||||
return false; // disk error
|
||||
}
|
||||
//log_v("Write lba: %ld\toffset: %ld\tbufsize: %ld", lba, offset, bufsize);
|
||||
// Serial.printf("Write lba: %ld\toffset: %ld\tbufsize: %ld\n", lba, offset, bufsize);
|
||||
for (int x = 0; x < bufsize / secSize; x++) {
|
||||
uint8_t blkbuffer[secSize];
|
||||
memcpy(blkbuffer, (uint8_t *)buffer + secSize * x, secSize);
|
||||
if (!SD_MMC.writeRAW(blkbuffer, lba + x)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return bufsize;
|
||||
}
|
||||
|
||||
static int32_t onRead(uint32_t lba, uint32_t offset, void *buffer, uint32_t bufsize) {
|
||||
uint32_t secSize = SD_MMC.sectorSize();
|
||||
if (!secSize) {
|
||||
return false; // disk error
|
||||
}
|
||||
//log_v("Read lba: %ld\toffset: %ld\tbufsize: %ld\tsector: %lu", lba, offset, bufsize, secSize);
|
||||
//Serial.printf("Read lba: %ld\toffset: %ld\tbufsize: %ld\tsector: %lu\n", lba, offset, bufsize, secSize);
|
||||
for (int x = 0; x < bufsize / secSize; x++) {
|
||||
if (!SD_MMC.readRAW((uint8_t *)buffer + (x * secSize), lba + x)) {
|
||||
return false; // outside of volume boundary
|
||||
}
|
||||
}
|
||||
return bufsize;
|
||||
}
|
||||
|
||||
static bool onStartStop(uint8_t power_condition, bool start, bool load_eject) {
|
||||
log_i("Start/Stop power: %u\tstart: %d\teject: %d", power_condition, start, load_eject);
|
||||
return true;
|
||||
}
|
||||
|
||||
// static void usbEventCallback(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) {
|
||||
// if (event_base == ARDUINO_USB_EVENTS) {
|
||||
// arduino_usb_event_data_t *data = (arduino_usb_event_data_t *)event_data;
|
||||
// switch (event_id) {
|
||||
// case ARDUINO_USB_STARTED_EVENT: Serial.println("USB PLUGGED"); break;
|
||||
// case ARDUINO_USB_STOPPED_EVENT: Serial.println("USB UNPLUGGED"); break;
|
||||
// case ARDUINO_USB_SUSPEND_EVENT: Serial.printf("USB SUSPENDED: remote_wakeup_en: %u\n", data->suspend.remote_wakeup_en); break;
|
||||
// case ARDUINO_USB_RESUME_EVENT: Serial.println("USB RESUMED"); break;
|
||||
|
||||
// default: break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
void setupmsc() {
|
||||
msc.vendorID("ESP32123");
|
||||
msc.productID("USB_MSC123");
|
||||
msc.productRevision("1.0");
|
||||
msc.onRead(onRead);
|
||||
msc.onWrite(onWrite);
|
||||
msc.onStartStop(onStartStop);
|
||||
msc.mediaPresent(true);
|
||||
msc.begin(SD_MMC.numSectors(), SD_MMC.sectorSize());
|
||||
|
||||
|
||||
vTaskDelay(100);
|
||||
|
||||
|
||||
USB.begin();
|
||||
USB.onEvent(usbEventCallback);
|
||||
}
|
||||
|
||||
// void loop() {
|
||||
// delay(-1);
|
||||
// }
|
||||
|
||||
void stopmsc()
|
||||
{
|
||||
msc.end();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void myusb_init() {
|
||||
// 初始化 USB
|
||||
USB.begin();
|
||||
|
||||
// 注册事件回调函数
|
||||
USB.onEvent(usbEventCallback);
|
||||
}
|
||||
18
src/mymsc.h
Normal file
18
src/mymsc.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef MYMSC_H
|
||||
#define MYMSC_H
|
||||
|
||||
#include <Arduino.h>
|
||||
// #include <SPI.h>
|
||||
// #include <SD.h>
|
||||
// #include <FS.h>
|
||||
// #include <SD_MMC.h>
|
||||
// #include <SPIFFS.h>
|
||||
// #include "sd_card.h"
|
||||
|
||||
|
||||
void setupmsc();
|
||||
void stopmsc();
|
||||
|
||||
void myusb_init();
|
||||
#endif
|
||||
|
||||
@ -2,13 +2,24 @@
|
||||
uint8_t channel;
|
||||
float now_angle,servo_offset_angle_up = 0,servo_offset_angle_down = 0;
|
||||
|
||||
uint8_t servo_pwm_pin;
|
||||
void servo_init(uint8_t servo_pin,uint8_t servo_channel)
|
||||
{
|
||||
pinMode(Shutter_pin1, OUTPUT);
|
||||
pinMode(Shutter_pin2, OUTPUT);
|
||||
digitalWrite(Shutter_pin1, LOW);
|
||||
digitalWrite(Shutter_pin2, LOW);
|
||||
|
||||
|
||||
int servo_freq = 50; // 频率(20ms周期)
|
||||
int servo_resolution = 12; // 分辨率(8 ~ 16)
|
||||
channel = servo_channel;
|
||||
ledcSetup(servo_channel, servo_freq, servo_resolution);
|
||||
ledcAttachPin(servo_pin, servo_channel);
|
||||
// ledcSetup(servo_channel, servo_freq, servo_resolution);
|
||||
// ledcAttachPin(servo_pin, servo_channel);
|
||||
// ledcAttach(servo_pin,servo_freq,servo_resolution);
|
||||
ledcAttachChannel(servo_pin,servo_freq,servo_resolution,0);
|
||||
servo_pwm_pin = servo_pin;
|
||||
|
||||
servo_set_angle(0);
|
||||
}
|
||||
|
||||
@ -24,13 +35,14 @@ int calculatePWM(float degree)
|
||||
|
||||
void servo_off()
|
||||
{
|
||||
ledcWrite(channel,0);
|
||||
ledcWrite(servo_pwm_pin,0);
|
||||
}
|
||||
|
||||
void servo_set_angle(float angle)
|
||||
{
|
||||
now_angle = angle;
|
||||
ledcWrite(channel, calculatePWM(angle));
|
||||
// ledcWrite(channel, calculatePWM(angle));
|
||||
ledcWrite(servo_pwm_pin, calculatePWM(angle)); // 写入 PWM 占空比
|
||||
}
|
||||
//获取舵机的角度
|
||||
float servo_get_angle()
|
||||
@ -42,6 +54,7 @@ void servo_up()
|
||||
{
|
||||
float a = 180 + servo_offset_angle_up;
|
||||
if(a < 0 || a > 270) a = 180;
|
||||
Serial0.printf("up %f,offset %f\n",a,servo_offset_angle_up);
|
||||
// servo_set_angle(200);
|
||||
// servo_set_angle(213);
|
||||
servo_set_angle(a);
|
||||
@ -51,10 +64,31 @@ void servo_down()
|
||||
{
|
||||
float a = 0 + servo_offset_angle_down;
|
||||
if(a < 0 || a > 270) a = 0;
|
||||
Serial0.printf("down %f,offset %f\n",a,servo_offset_angle_down);
|
||||
// servo_set_angle(12);
|
||||
// servo_set_angle(28);
|
||||
servo_set_angle(a);
|
||||
}
|
||||
|
||||
|
||||
void shutter_up()
|
||||
{
|
||||
digitalWrite(Shutter_pin1, HIGH);
|
||||
digitalWrite(Shutter_pin2, LOW);
|
||||
}
|
||||
void shutter_down()
|
||||
{
|
||||
digitalWrite(Shutter_pin2, HIGH);
|
||||
digitalWrite(Shutter_pin1, LOW);
|
||||
}
|
||||
|
||||
void shutter_off()
|
||||
{
|
||||
digitalWrite(Shutter_pin1, LOW);
|
||||
digitalWrite(Shutter_pin2, LOW);
|
||||
}
|
||||
|
||||
|
||||
/// @brief
|
||||
/// @param dir 0 down 1 up
|
||||
/// @param angle
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
#ifndef _SERVO_H_
|
||||
#define _SERVO_H_
|
||||
|
||||
#define Shutter_pin1 5
|
||||
#define Shutter_pin2 6
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
@ -13,4 +15,7 @@ void servo_up();
|
||||
void servo_down();
|
||||
void servo_offset(float angle,uint8_t dir);
|
||||
|
||||
void shutter_up();
|
||||
void shutter_down();
|
||||
void shutter_off();
|
||||
#endif
|
||||
@ -28,3 +28,21 @@ uint8_t get_tuigan_status()
|
||||
return tuigan_sta;
|
||||
}
|
||||
|
||||
|
||||
bool check_tuigan()
|
||||
{
|
||||
uint8_t tuigan;
|
||||
pinMode(tuigan_chek_pin, INPUT_PULLUP);
|
||||
if(digitalRead(tuigan_chek_pin) == LOW)
|
||||
{
|
||||
tuigan = tui;
|
||||
}
|
||||
else
|
||||
{
|
||||
tuigan = suo;
|
||||
}
|
||||
|
||||
if(tuigan != tuigan_sta) return false;
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include "Arduino.h"
|
||||
#include "my74hc595.h"
|
||||
|
||||
#define tuigan_chek_pin 38
|
||||
enum tuigan_status
|
||||
{
|
||||
tui,
|
||||
@ -12,6 +13,6 @@ enum tuigan_status
|
||||
|
||||
void tuigan(enum tuigan_status status);
|
||||
uint8_t get_tuigan_status();
|
||||
|
||||
bool check_tuigan();
|
||||
#endif
|
||||
|
||||
|
||||
@ -118,8 +118,6 @@ void UpDateClassByme::updateversion()
|
||||
}
|
||||
bool UpDateClassByme::CheckAndUpdate()
|
||||
{
|
||||
|
||||
|
||||
String Targetversion=GetValueFromNet("/weather/php/GetVserion.php",StationID);
|
||||
if ( Targetversion=="0"||Targetversion==CurrentVersion||Targetversion=="")
|
||||
{
|
||||
@ -134,7 +132,7 @@ bool UpDateClassByme::CheckAndUpdate()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Serial.println("count download is:"+String(countdownload1));
|
||||
Serial.println("count download is:"+String(countdownload1));
|
||||
|
||||
String MD5=GetValueFromNet("/weather/php/GetMD5Value.php",Targetversion);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user