This commit is contained in:
2026-08-12 13:33:31 +08:00
parent 0f8fc28d05
commit 82697e1460
5 changed files with 413 additions and 458 deletions

View File

@ -13,6 +13,8 @@
[env:esp32-s3-devkitc-1]
platform = http://172.16.0.251/esp32/platform-espressif32_arduino3.1.1.zip
; platform = espressif32 @ 6.5.0
board = esp32-s3-devkitc-1
framework = arduino
@ -44,7 +46,7 @@ lib_deps =
build_flags = -DARDUINO_USB_CDC_ON_BOOT=1 ; Enable USB CDC
-DCORE_DEBUG_LEVEL=1 ; Set debug level
-DCONFIG_ESP_PANIC_HANDLER_REBOOT=y
board_build.partitions = partitions.csv
board_build.filesystem = spiffs

View File

@ -97,7 +97,6 @@ void GSMMannger::loop()
if (!modem->isNetworkConnected())
{
SerialMon.println("Network disconnected");
if (!modem->waitForNetwork(20000L, true))
{

View File

@ -43,7 +43,7 @@ STRSensorInfo SensorIS11::initSensor()
STRSensorInfo SensorIS11::GetSensorInfo()
{
// Serial.println("init ok");
// write_log(log_path,"init isSensorInit",10);
write_log(log_path,"init isSensorInit",10);
STRSensorInfo setem;
if (!isSensorInit())
{
@ -53,10 +53,10 @@ STRSensorInfo SensorIS11::GetSensorInfo()
}
// write_log(log_path,"init ok",10);
write_log(log_path,"init ok",10);
int retlenth= SendGetSensorInfo((u_char *)GET_SERIAL_NUMBER,sizeof(GET_SERIAL_NUMBER));
vTaskDelay(100);
// write_log(log_path,String(retlenth),10);
write_log(log_path,String(retlenth),10);
char * result=new char[retlenth];
memcpy(result,DataRetrun+3,retlenth);
@ -67,8 +67,8 @@ STRSensorInfo SensorIS11::GetSensorInfo()
delete[] result;
// Serial.println(String(setem.serialnumber.c_str()));
// write_log(log_path,"serialnumber :"+String(setem.serialnumber.c_str()),10);
// write_log(log_path,"serialnumber :"+setem.serialnumber,10);
write_log(log_path,"serialnumber :"+String(setem.serialnumber.c_str()),10);
write_log(log_path,"serialnumber :"+setem.serialnumber,10);
retlenth= SendGetSensorInfo((u_char *)GET_PRODUCT_NAME,sizeof(GET_PRODUCT_NAME));
vTaskDelay(100);
result=new char[retlenth];
@ -77,15 +77,15 @@ STRSensorInfo SensorIS11::GetSensorInfo()
// result[4]='\0';
// std::string str1(result);
// write_log(log_path,"productname :"+String(setem.SensorName.c_str()),10);
write_log(log_path,"productname :"+String(setem.SensorName.c_str()),10);
setem.SensorName = String(result);
// write_log(log_path,"productname :"+setem.SensorName,10);
write_log(log_path,"productname :"+setem.SensorName,10);
delete result;
setem.BandNum=2048;
// Serial.println(String(setem.SensorName.c_str())+"_"+String(setem.serialnumber.c_str()));
// write_log(log_path,String(setem.SensorName.c_str())+"_"+String(setem.serialnumber.c_str()),10);
write_log(log_path,String(setem.SensorName.c_str())+"_"+String(setem.serialnumber.c_str()),10);
setem.maxValue=65535;
setem.wavelenthlist = new float[setem.BandNum]();
@ -94,7 +94,7 @@ STRSensorInfo SensorIS11::GetSensorInfo()
float a[4];
memcpy(a,DataRetrun+3,16);
// write_log(log_path,"CoverLittleAndBig",10);
write_log(log_path,"CoverLittleAndBig",10);
CoverLittleAndBig((char *)a,4*sizeof(float));
int bandsss= setem.BandNum;
#ifdef ARDUINO
@ -109,7 +109,7 @@ STRSensorInfo SensorIS11::GetSensorInfo()
// Serial.print(" a3:");
// Serial.println(a[3]);
// write_log(log_path,"ARDUINO",10);
// write_log(log_path,"a0:"+String(a[0])+" a1:"+String(a[1])+" a2:"+String(a[2])+" a3:"+String(a[3]),10);
write_log(log_path,"a0:"+String(a[0],10)+" a1:"+String(a[1],10)+" a2:"+String(a[2],10)+" a3:"+String(a[3],10),10);
#endif
setem.a1=a[0];
@ -1475,16 +1475,6 @@ void SensorIS11::advanced_mode(u_int32_t direction,u_int32_t shutter_time,u_int3
if(direction == 1 && flag)
{
// "a0": -1.37016491e-9,
// "a1": -0.000052,
// "a2": 0.440364,
// "a3": 348.4284,
// "b0": -1.2597071e-9,
// "b1": -0.000053,
// "b2": 0.440609,
// "b3": 348.3989
const int numValues = SensorInfo.BandNum;
float xValues[2048];
float *yValues;
@ -1495,18 +1485,11 @@ void SensorIS11::advanced_mode(u_int32_t direction,u_int32_t shutter_time,u_int3
double b3 = SensorIS11::guangpu_bochang.b3;
write_log(log_path,"bochang:"+String(b0,4)+" "+String(b1,4)+" "+String(b2,4)+" "+String(b3,4),10);
yValues = IS11_datastructure_avn->data;
// for (uint32_t i = 0; i < 2048; i++)
// {
// xValues[i] = b0 * i * i * i + b1 * i * i + b2 * i+ b3;
// // yValues[i] = IS11_datastructure_avn->data[i];
// }
for (uint32_t i = 0; i < 2048; i++)
{
// xValues[i] = b0 * i * i * i + b1 * i * i + b2 * i+ b3;
double p_up = SensorInfo.a1 * i * i * i + SensorInfo.a2 * i * i + SensorInfo.a3 * i+ SensorInfo.a4;
// xValues[i] = p_up + (-2.999e-7 * p_up*p_up + 0.0009475 * p_up - 0.48467);
xValues[i] = p_up + (9.4755e-11*p_up*p_up*p_up - 6.0470e-07*p_up*p_up + 0.0012166*p_up - 0.53644);
IS11_datastruct_down.data[i] = DATABUFF[i];
}

View File

@ -37,54 +37,57 @@ void callback(char* topic, byte* payload, unsigned int length) {
{
receive_command_unpack(read_buff,length,2);
}
// mqtt_write(read_buff,length);
}
void reconnect() {
bool reconnect()
{
const char *subscribe_topic = str_subscribe_topic.c_str();
// 重新连接MQTT
uint32_t cout = 0;
while (!mqtt_client->connected())
{
// Serial.print("Attempting MQTT connection...");
vTaskDelay(10);
if (mqtt_client->connect(str_mqtt_client_id.c_str()))
{
// Serial.println("connected");
Serial.println("Attempting MQTT connected");
mqtt_client->subscribe(subscribe_topic);
// return true;
break;
}
else
cout ++;
if (cout == 10)
{
// Serial.print("failed, rc=");
// Serial.print(mqtt_client->state());
// break;
return false;
}
// vTaskDelay(100);
}
return true;
}
void gsmm_mqtt_loop_task(void *pvParameters)
{
while (1)
{
bool reconnect_flag = true;
if (!mqtt_client->connected()) {
reconnect();
reconnect_flag = reconnect();
}
if(reconnect_flag) mqtt_client->loop();
gsmmanger->loop();
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);
/////////////////////////////////////////////////////////////
@ -118,6 +121,7 @@ void gsmm_mqtt_init(String sensor_id)
// //Serial.println("Failed to create event group");
// }
gsmmanger = new GSMMannger(SIMUARTNUMER, SIMUART_RX, SIMUART_TX);
gsmmanger->client->setTimeout(1000 * 20);
mqtt_client = new PubSubClient(*gsmmanger->client); // 初始化 PubSubClient;
mqtt_client->setBufferSize(1024);
mqtt_client->setServer(mqtt_server, mqtt_port);
@ -125,6 +129,7 @@ void gsmm_mqtt_init(String sensor_id)
// 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*5,NULL, 1, NULL, 1);
}
@ -154,12 +159,15 @@ void mqtt_write(uint8_t *data , uint32_t lenth)
bool UpdateData(String path,uint8_t *data, size_t lenth, String Contenttype )
{
EventBits_t uxBits = xEventGroupGetBits(http_event_group);
uint32_t cout = 0;
while (uxBits & mqtt_stop_bit)
{
uxBits = xEventGroupGetBits(http_event_group);
cout ++;
if(cout == (180 * 1000) ) return false;
vTaskDelay(1);
}
xEventGroupSetBits(http_event_group, mqtt_stop_bit);
xEventGroupWaitBits(http_event_group, Http_start_bit,pdTRUE, pdFALSE,portMAX_DELAY);
http->beginRequest();
@ -169,7 +177,6 @@ bool UpdateData(String path,uint8_t *data, size_t lenth, String 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);
@ -217,12 +224,17 @@ bool UpdateData(String path,uint8_t *data, size_t lenth, String Contenttype )
String getnetData()
{
EventBits_t uxBits = xEventGroupGetBits(http_event_group);
uint32_t cout = 0;
while (uxBits & mqtt_stop_bit)
{
uxBits = xEventGroupGetBits(http_event_group);
cout ++;
if(cout == (180 * 1000) ) return "-1";
vTaskDelay(1);
}
xEventGroupSetBits(http_event_group, mqtt_stop_bit);
xEventGroupWaitBits(http_event_group, Http_start_bit,pdTRUE, pdFALSE,portMAX_DELAY);
@ -330,10 +342,15 @@ gps_struct parseQGPSLOCFull(String gpsStr) {
String get_GPS(gps_struct *gps_info)
{
EventBits_t uxBits = xEventGroupGetBits(http_event_group);
uint32_t cout = 0;
while (uxBits & mqtt_stop_bit)
{
uxBits = xEventGroupGetBits(http_event_group);
cout ++;
if(cout == (180 * 1000) ) return "-1";
vTaskDelay(1);
}
xEventGroupSetBits(http_event_group, mqtt_stop_bit);
@ -406,11 +423,14 @@ void Update_firmware(Stream &updateSource, size_t updateSize)
//Serial.println("Restart ESP device!");
// abort();
// ESP.restart();
write_log(log_path,"OTA success!",10);
write_log(log_path,"Restart ESP device!",10);
vTaskDelay(100);
esp_restart();
}
else
{
//Serial.println("OTA not fiished");
Serial.println("OTA not filed");
}
}
else
@ -502,6 +522,7 @@ bool check_file_ota(String MD5)
file.close();
if (MD5 == md5com)
{
write_log(log_path,"md5 check ok",10);
file = SD_MMC.open("/update.bin", "rb");
Update_firmware(file,countdownload1);
return true;
@ -518,10 +539,25 @@ bool check_file_ota(String MD5)
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);
// }
EventBits_t uxBits = xEventGroupGetBits(http_event_group);
uint32_t cout = 0;
while (uxBits & mqtt_stop_bit)
{
uxBits = xEventGroupGetBits(http_event_group);
cout ++;
if(cout == (180 * 1000) )
{
write_log(log_path,"OTA filed,reboot ...",10);
vTaskDelay(3000);
esp_restart();
}
vTaskDelay(1);
}

View File

@ -1,5 +1,6 @@
#include "head.h"
#include "esp_task_wdt.h"
#define WDT_TIMEOUT (10 * 60*1000)
// #define GPS_4G
EventGroupHandle_t Main_EventGroup;
@ -26,10 +27,11 @@ void Task2(void *pvParameters);
任务名task_4G_mode
任务功能4G模式
*/
TaskHandle_t A4G_Handler;
void open_4G_mode(uint32_t up);
// TaskHandle_t A4G_Handler;
TaskHandle_t OTA_Handler;
void task_4G_mode(void *pvParameters);
// void task_4G_mode(void *pvParameters);
void OTA_task(void *pvParameters);
//work_mode 0:手动 1时间模式 time_mode 2高级模式 advanced_mode 3:low_power_mode 44G_mode
//caiji_mode 0停止 1单次 2连续 3定标 4高级模式 5回传数据 6低功耗模式
@ -45,6 +47,9 @@ volatile u_int32_t work_mode = 0,caiji_mode = 0,return_mode = 1,atuo_return = 0,
volatile float start_time = 0.1,stop_time = 23.59,maximum_temperature = 10,Minimum_temperature = 0,sun_latitude,sun_longitude;
volatile float sunrise, sunset;
volatile float calculation_bochang1,calculation_bochang2;
volatile u_int32_t save = false;
volatile u_int32_t up_data = 0;
// volatile u_int32_t http_flag = 0;
/// @brief 高级模式参数
@ -284,8 +289,8 @@ void setup()
// is11Sensor->guangpu_bochang.a1 = 0.000000000000000;
// is11Sensor->guangpu_bochang.a2 = 0.000000000;
sys_sd_doc["firmware"] = "V2.0.8";
sys_sd_doc["version"] = "V2.0.8";
sys_sd_doc["firmware"] = "V2.1.0";
sys_sd_doc["version"] = "V2.1.0";
sys_info_init();
// dingbiao_init("/dingbiao/dingbiao_up_gain.bin");
@ -304,15 +309,6 @@ void setup()
// myusb_init();
// setupmsc();
/* code */
servo_up();
vTaskDelay(1000 * 1.5);
// servo_set_angle(0);
servo_down();
vTaskDelay(1000 * 1.5);
beep_run(2000,1000);
vTaskDelay(1000 * 1.5);
beep_stop();
Main_EventGroup = xEventGroupCreate();
@ -332,6 +328,10 @@ void setup()
is11Sensor->SensorInfo.a3 = is11Sensor->guangpu_bochang.a2;
is11Sensor->SensorInfo.a4 = is11Sensor->guangpu_bochang.a3;
}
else
{
}
}
else
{
@ -344,40 +344,55 @@ void setup()
}
// if(sys_sd_doc["status_4g"] == "open_4g")
// {
// gsmm_mqtt_init(STRSensorInfos_structure.serialnumber);
// xTaskCreatePinnedToCore(task_4G_mode, "task_4G_mode",1024*23,NULL, 1,&A4G_Handler, 1);
// xTaskCreatePinnedToCore(OTA_task , "OTA_task",1024*4 ,NULL, 1,&OTA_Handler, 1);
// }
// else
// {
// xTaskCreatePinnedToCore(Task0,"Task0",1024 * 23,NULL,2,&Task0_Handler, 0);
// }
if(sys_sd_doc["status_4g"] == "open_4g")
{
gsmm_mqtt_init(STRSensorInfos_structure.serialnumber);
xTaskCreatePinnedToCore(task_4G_mode, "task_4G_mode",1024*23,NULL, 1,&A4G_Handler, 1);
xTaskCreatePinnedToCore(OTA_task , "OTA_task",1024*4 ,NULL, 1,&OTA_Handler, 1);
}
else
{
xTaskCreatePinnedToCore(Task0,"Task0",1024 * 23,NULL,2,&Task0_Handler, 0);
}
if (xMutexInventory == NULL)
{
}
else
{
//创建并启动Core1的任务 xTaskCreatePinnedToCore
// xTaskCreatePinnedToCore(Task0,"Task0",1024 * 23,NULL,2,&Task0_Handler, 0);
xTaskCreatePinnedToCore(Task1,"Task1",1024 * 5, NULL,1,&Task1_Handler, 0);
xTaskCreatePinnedToCore(Task2,"Task2",1024 * 30,NULL,5,&Task2_Handler, 1);
}
xTaskCreatePinnedToCore(Task0,"Task0",1024 * 30,NULL,2,&Task0_Handler, 1);
xTaskCreatePinnedToCore(Task1,"Task1",1024 * 15, NULL,1,&Task1_Handler, 1);
xTaskCreatePinnedToCore(Task2,"Task2",1024 * 20,NULL,5,&Task2_Handler, 0);
// write_log(log_path,"setup ok",10);
esp_task_wdt_config_t twdt_config = {
.timeout_ms = WDT_TIMEOUT,
.idle_core_mask = (1 << 1) | (1 << 0),
.trigger_panic = true,
};
esp_task_wdt_deinit();
esp_err_t err = esp_task_wdt_init(&twdt_config);
write_log(log_path,"esp_task_wdt_init: " + String(esp_err_to_name(err)),10);
// esp_task_wdt_add(Task1_Handler);
servo_up();
vTaskDelay(1000 * 1.5);
// servo_set_angle(0);
servo_down();
vTaskDelay(1000 * 1.5);
beep_run(2000,1000);
vTaskDelay(1000 * 1.5);
beep_stop();
}
void loop()
{
vTaskDelay(10000);
vTaskDelay(portMAX_DELAY);
// uint32_t cba = 0;
// String stra = getnetData();;
@ -387,16 +402,47 @@ void loop()
}
void Task0(void *pvParameters)
{
vTaskDelay(1);
vTaskDelay(10);
write_log(log_path,"task 0",10);
uint32_t uint_work_task0 = 100;
while (1)
{
if(work_mode == 4)
{
vTaskDelay(5);
rtc.getDateTime(&now);
float now_time = now.hour + now.minute/100;
float start = 7;
float stop = 19;
if(sys_sd_doc["work_time"] = "gps")
{
start = sunrise;
stop = sunset;
write_log(log_path,"work_time gps",10);
}
else if(sys_sd_doc["work_time"] = "manual")
{
start = start_time;
stop = stop_time;
write_log(log_path,"manual",10);
}
write_log(log_path,"\n now_time:" + String(now_time) + "\n start:" + String(start) + "\n stop:" + String(stop),10);
if((now_time >= start) && (now_time < stop))
{
is11Sensor->TakeOneJob();
is11Sensor->get_fanshelv();
if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS)
{
up_data = 1;
xSemaphoreGive(xMutexInventory);
}
}
// vTaskDelay(5);
vTaskDelay(1000 * time_interval);
continue;
}
if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS)
{
if(uint_work_task0 == 100 && caiji_mode != 2)
@ -457,7 +503,6 @@ void Task0(void *pvParameters)
caiji_state = 2;
xSemaphoreGive(xMutexInventory);
}
is11Sensor->advanced_mode(advanced_direction,advanced_shutter_time,advanced_collect_times,advanced_remove_dark);
uint_work_task0 = 100;
break;
@ -495,111 +540,75 @@ void Task0(void *pvParameters)
//Task1的实现
void Task1(void *pvParameters)
{
vTaskDelay(3);
vTaskDelay(1);
write_log(log_path,"task 1",10);
uint8_t last_day = 100;
// uint8_t last_day = 100;
uint32_t count = 10;
uint32_t running_count = 0;
uint32_t day_count = 0;
uint8_t last_day = 0;
esp_task_wdt_add(NULL);
while(1)
{
//Serial.println("Task1 is running");
rtc.getDateTime(&now);
write_log(log_path, String(now.year) +"."+ String(now.month) +"."+ String(now.day)+" "+String(now.hour)+":"+String(now.minute)+":"+String(now.second),20);
// String path = "/guangpu_data/"+ String(now.year) + "/" + String(now.month) + "/" + String(now.day);
// if(!SD_MMC.exists(log_path))
// write_log(log_path,"esp_task_wdt_reset",10);
esp_task_wdt_reset();
//////////////////////////////////////////////////////////////////////////////////////////////////////////
double cardSize = SD_MMC.cardSize() / (1024 * 1024);
double used_size = SD_MMC.usedBytes() / (1024 * 1024);
float used_percent = used_size / cardSize;
// write_log(log_path,"used_percent: " + String(used_percent),10);
//数据清除规则:1、满十年清除第一年数据 2、当数据>90%时删除最前一个月数据
if(used_percent >= 0.8)
uint32_t up_data_flag = 0;
if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS)
{
if (used_percent >= 0.9)
up_data_flag = up_data;
up_data = 0;
xSemaphoreGive(xMutexInventory);
}
if(sys_sd_doc["status_4g"] == "open_4g")
{
if((running_count == 10) || (up_data_flag > 0))
{
//删除文件
String path_b = "/gaugpu_data";
for(int i=24;i<255 ;i++)
Serial.println("Task1 is running");
open_4G_mode(up_data_flag);
}
}
else
{
if(running_count == 10)
{
rtc.getDateTime(&now);
write_log(log_path,"running_count " + String(running_count),20);
write_log(log_path, String(now.year) +"."+ String(now.month) +"."+ String(now.day)+" "+String(now.hour)+":"+String(now.minute)+":"+String(now.second),20);
}
}
if(running_count == 0)
{
double cardSize = SD_MMC.cardSize() / (1024 * 1024);
double used_size = SD_MMC.usedBytes() / (1024 * 1024);
float used_percent = used_size / cardSize;
// write_log(log_path,"used_percent: " + String(used_percent),10);
//数据清除规则:1、满十年清除第一年数据 2、当数据>90%时删除最前一个月数据
if(used_percent >= 0.8)
{
if (used_percent >= 0.9)
{
for (uint8_t j = 1; j < 13; j++)
//删除文件
String path_b = "/gaugpu_data";
for(int i=24;i<255 ;i++)
{
String path_a = path_b + "/" +String(i)+ "/" +String(j);
if(SD_MMC.exists(path_a))
for (uint8_t j = 1; j < 13; j++)
{
rm_dir_or_file(path_a.c_str());
String path_a = path_b + "/" +String(i)+ "/" +String(j);
if(SD_MMC.exists(path_a))
{
rm_dir_or_file(path_a.c_str());
}
}
}
}
//报警
write_log(log_path,"sdcard will full," + String(used_percent * 100) + "%" +"used.",20);
}
//报警
write_log(log_path,"sdcard will full," + String(used_percent * 100) + "%" +"used.",20);
}
// if(SD_MMC.exists("/data/" + String(now.year - 10) ))
// {
// String path = "/data/" + String(now.year - 10);
// rm_dir_or_file(path.c_str());
// }
#ifdef GPS_4G
if(now.day != last_day)
{
// 获取网络时间
gps_struct net_structure;
String net_date = getnetData();
write_log(log_path,"net_date is :"+net_date,10);
// 2024-07-12 07:12:45
//截取时间
if(net_date != "-1")
{
net_structure.year = net_date.substring(0,4).toInt() - 2000;
net_structure.month = net_date.substring(5,7).toInt();
net_structure.day = net_date.substring(8,10).toInt();
net_structure.hour = net_date.substring(11,13).toInt();
net_structure.minute = net_date.substring(14,16).toInt();
net_structure.second = net_date.substring(17,-1).toInt();
if(now.year != net_structure.year || now.month != net_structure.month || now.day != net_structure.day || now.hour - net_structure.hour || (fabs(now.minute - net_structure.minute)>5 ))
{
now.year = net_structure.year;
now.month = net_structure.month;
now.day = net_structure.day;
now.hour = net_structure.hour;
now.minute = net_structure.minute;
now.second = net_structure.second;
rtc.setDateTime(&now);
}
last_day = now.day;
}
else
{
////获取GPS
gps_struct gps_structure;
String gpsbac = get_GPS(&gps_structure);
if(gpsbac == "-1") write_log(log_path,"no gps",10);
if(net_date != "-1" && gpsbac != "-1")
{
gps_structure.year = gps_structure.year - 2000;
if(now.year != gps_structure.year || now.month != gps_structure.month || now.day != gps_structure.day || now.hour != gps_structure.hour || (fabs(now.minute - net_structure.minute)>5 ))
{
now.year = gps_structure.year;
now.month = gps_structure.month;
now.day = gps_structure.day;
now.hour = gps_structure.hour;
now.minute = gps_structure.minute;
now.second = gps_structure.second;
rtc.setDateTime(&now);
}
last_day = now.day;
}
}
rtc.getDateTime(&now);
}
#endif
//获取时间
if(sys_sd_doc["work_mode"] == "time_mode")
@ -616,10 +625,9 @@ void Task1(void *pvParameters)
caiji_mode = 0;
xSemaphoreGive(xMutexInventory);
}
}
}
vTaskDelay(1000 * 1);
// 推杆
// 日出日落控制 太阳升起前推杆缩,太阳落下后推杆伸
@ -639,7 +647,7 @@ void Task1(void *pvParameters)
write_log(log_path,"sunrise: " + String((int)sunrise),log_level);
write_log(log_path,"sunset: " + String((int)sunset),log_level);
write_log(log_path,"tuisuotime: " + String(tuisuotime),log_level);
if(sunrise<0)
{
sunrise = sunrise + 24;
@ -687,68 +695,55 @@ void Task1(void *pvParameters)
jiaresi(6,stop_jiare);
}
}
vTaskDelay(100);
float temperature[8];
getall_temp(temperature);
// vTaskDelay(100);
// getall_temp(temperature);
// vTaskDelay(100);
// getall_temp(temperature);
for(uint8_t n=0; n<8 ;n++)
{
if(temperature[n] < -120) write_log(log_path,"temperature " + String(n+1) +":" + String(temperature[n])+"This sensor is broken.",20);
if(count == 10)
float temperature[8];
getall_temp(temperature);
for(uint8_t n=0; n<8 ;n++)
{
write_log(log_path,"temperature " + String(n) +":" + String(temperature[n]),20);
count = 0;
}else
write_log(log_path,"temperature " + String(n) +":" + String(temperature[n]),10);
}
if(temperature[2] > maximum_temperature)
{
write_log(log_path,"stop_jiare",20);
jiaresi(7,stop_jiare);
}
if( temperature[2] < Minimum_temperature)
{
if(temperature[2] < -110)
if(temperature[n] < -120) write_log(log_path,"temperature " + String(n+1) +":" + String(temperature[n])+"This sensor is broken.",20);
if(count == 10)
{
write_log(log_path,"temperature " + String(n) +":" + String(temperature[n]),20);
count = 0;
}else
write_log(log_path,"temperature " + String(n) +":" + String(temperature[n]),10);
}
if(temperature[2] > maximum_temperature)
{
write_log(log_path,"temperature 2 is broken.",20);
write_log(log_path,"stop_jiare",20);
jiaresi(7,stop_jiare);
}
else
{
write_log(log_path,"start_jiare",20);
jiaresi(7,start_jiare);
}
}
// vTaskDelay(1000 * 1);
// sdcard::Mkdir(path);
// float temp4 = getone_temp(4);
// float temp6 = getone_temp(6);
// write_log(log_path,"temp4 : ",10);
// write_log(log_path,"temp6 : " + String(temp6),10);
// if((temp4+temp6)/2 < 0)
// {
// write_log(log_path,"start jiaresi",10);
// // jiaresi(5,start_jiare);
// vTaskDelay(1000 * 10);
// }
// else if ((temp4+temp6)/2 > 5)
// {
// write_log(log_path,"stop jiaresi",10);
// // jiaresi(5,stop_jiare);
// }
count++;
vTaskDelay(1000 * 60 );
if( temperature[2] < Minimum_temperature)
{
if(temperature[2] < -110)
{
write_log(log_path,"temperature 2 is broken.",20);
jiaresi(7,stop_jiare);
}
else
{
write_log(log_path,"start_jiare",20);
jiaresi(7,start_jiare);
}
}
if(day_count == 0) last_day = now.day;
if(last_day != now.day)
{
esp_restart();
}
// running_count = 0;
count++;
}
running_count++;
if(running_count > 120) running_count = 0;
vTaskDelay(1000);
}
}
// Task2的实现
@ -782,7 +777,23 @@ void Task2(void *pvParameters)
{
receive_command_unpack(read_buf,data_length,1);
}
// vTaskDelay(1);
if(save == true)
{
if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS)
{
String save_str = "";
serializeJson(sys_sd_doc, save_str);
write_log(log_path,"save_str: " + save_str,20);
File file;
file = SD_MMC.open("/system/system_info.json","w+");
file.println(save_str);
file.flush();
file.close();
save = false;
}
xSemaphoreGive(xMutexInventory);
}
}
}
@ -797,217 +808,143 @@ struct http_data_head
float is3_a3;
float is3_a4;
};
void task_4G_mode(void *pvParameters)
http_data_head http_head;
uint8_t *updata_buff = new u_char[sizeof(IS11_datastruct) + sizeof(http_head)];
void open_4G_mode(uint32_t up)
{
http_data_head http_head;
uint8_t *data = new u_char[sizeof(IS11_datastruct) + sizeof(http_head)];
write_log(log_path,"task 4G mode",10);
while (1)
write_log(log_path,"opne 4G" + String(up),10);
String time_4g = getnetData();
rtc.getDateTime(&now);
write_log(log_path,"time_4g: " + time_4g,10);
if(time_4g != "-1")
{
// Serial.println("task_4G_mode 11");
write_log(log_path,"task_4G_mode 11",10);
// vTaskDelay(1000 * 10);
bool warn_sta = false;
float temperature[8];
doc_4G["SN"] = STRSensorInfos_structure.serialnumber;
if(check_tuigan() == false )
uint32_t year = time_4g.substring(0,4).toInt() - 2000;
uint32_t month = time_4g.substring(5,7).toInt();
uint32_t day = time_4g.substring(8,10).toInt();
uint32_t hour = time_4g.substring(11,13).toInt();
uint32_t minute = time_4g.substring(14,16).toInt();
uint32_t second = time_4g.substring(17,-1).toInt();
hour = hour + 8;
if(hour > 23)
{
warn_sta = true;
doc_4G["tuigan"] = "warn";
if(get_tuigan_status() == tui)
{
doc_4G["tuigan_status"] = "tui";
}
else
{
doc_4G["tuigan_status"] = "suo";
}
}
float Voltage = adc_read();
//Serial.println("Voltage:" + String(Voltage));
if(Voltage < 10)
hour = hour - 24;
day = day + 1;
}
if(now.year != year || now.month != month || now.day != day || now.hour - hour || (fabs(now.minute - minute)>5 ))
{
warn_sta = true;
doc_4G["Voltage"] = "warn";
doc_4G["Voltage_value"] = Voltage;
now.year = year;
now.month = month;
now.day = day;
now.hour = hour;
now.minute = minute;
now.second = second;
rtc.setDateTime(&now);
}
////获取GPS
gps_struct gps_structure;
String gpsbac = get_GPS(&gps_structure);
if(gpsbac == "-1") write_log(log_path,"no gps",10);
else if(gpsbac != "-1")
{
if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS)
{
sun_latitude = gps_structure.latitude;
sun_longitude = gps_structure.longitude;
sys_sd_doc["gps_info"]["latitude"] = sun_latitude;
sys_sd_doc["gps_info"]["longitude"] = sun_longitude;
xSemaphoreGive(xMutexInventory);
}
}
}
if(up)
{
// uint8_t *data = new u_char[sizeof(IS11_datastruct) + sizeof(http_head)];
if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS)
{
String sn = STRSensorInfos_structure.serialnumber;
write_log(log_path,"task 4g sn: " + sn,10);
memset(&http_head,'\0',sizeof(http_head));
String version = sys_sd_doc["version"] ;
memcpy(http_head.sn,sn.c_str(),sn.length());
memcpy(http_head.version,version.c_str(),version.length());
http_head.sn[sn.length()] = '\0';
http_head.version[version.length()] = '\0';
http_head.lat = sun_latitude;
http_head.lon = sun_longitude;
http_head.is3_a1 = is11Sensor->SensorInfo.a1;
http_head.is3_a2 = is11Sensor->SensorInfo.a2;
http_head.is3_a3 = is11Sensor->SensorInfo.a3;
http_head.is3_a4 = is11Sensor->SensorInfo.a4;
xSemaphoreGive(xMutexInventory);
}
memcpy(updata_buff,&http_head,sizeof(http_head));
memcpy((updata_buff + sizeof(http_head)),&IS11_datastruct_fanshelv,sizeof(IS11_datastruct_fanshelv));
vTaskDelay(10);
write_log(log_path,"upload data to server",10);
UpdateData("/HyperspectralV2/DataUpload.php",updata_buff , sizeof(http_head) + sizeof(IS11_datastruct_fanshelv),HTTP_METHOD_POST);
}
bool warn_sta = false;
float temperature[8];
doc_4G["SN"] = STRSensorInfos_structure.serialnumber;
if(check_tuigan() == false )
{
warn_sta = true;
doc_4G["tuigan"] = "warn";
if(get_tuigan_status() == tui)
{
doc_4G["tuigan_status"] = "tui";
}
else
{
doc_4G["tuigan_status"] = "suo";
}
}
float Voltage = adc_read();
if(Voltage < 10)
{
warn_sta = true;
doc_4G["Voltage"] = "warn";
doc_4G["Voltage_value"] = Voltage;
}
// getall_temp(temperature);
for(uint8_t n=0; n<8 ;n++)
for(uint8_t n=0; n<8 ;n++)
{
temperature[n] = IS11_datastruct_fanshelv.temprature[n];
if((temperature[n] < -10) || (temperature[n] > 50))
{
temperature[n] = IS11_datastruct_fanshelv.temprature[n];
if((temperature[n] < -10) || (temperature[n] > 50))
{
warn_sta = true;
doc_4G["temperature"] = "warn";
doc_4G["temperature 0 : "] = temperature[0];
doc_4G["temperature 1 : "] = temperature[1];
doc_4G["temperature 2 : "] = temperature[2];
doc_4G["temperature 3 : "] = temperature[3];
doc_4G["temperature 4 : "] = temperature[4];
doc_4G["temperature 5 : "] = temperature[5];
doc_4G["temperature 6 : "] = temperature[6];
doc_4G["temperature 7 : "] = temperature[7];
break;
}
//Serial.println("uptodate temperature " + String(n) +":" + String(temperature[n]));
warn_sta = true;
doc_4G["temperature"] = "warn";
doc_4G["temperature 0 : "] = temperature[0];
doc_4G["temperature 1 : "] = temperature[1];
doc_4G["temperature 2 : "] = temperature[2];
doc_4G["temperature 3 : "] = temperature[3];
doc_4G["temperature 4 : "] = temperature[4];
doc_4G["temperature 5 : "] = temperature[5];
doc_4G["temperature 6 : "] = temperature[6];
doc_4G["temperature 7 : "] = temperature[7];
break;
}
if(warn_sta)
{
String data_info;
serializeJson(doc_4G,data_info);
UpdateData("/HyperspectralV2/warning.php",(uint8_t *)data_info.c_str() ,data_info.length() ,HTTP_METHOD_POST);
}
//获取时间
//Serial.println("work_mode = " + String(work_mode) );
if(work_mode == 4)
{
String time_4g = getnetData();
//Serial.println("time_4g " + time_4g);
rtc.getDateTime(&now);
//Serial.println("rtc time :" + String(now.year) + "-" + String(now.month) + "-" + String(now.day) + " " + String(now.hour) + ":" + String(now.minute) + ":" + String(now.second));
if(time_4g != "-1")
{
uint32_t year = time_4g.substring(0,4).toInt() - 2000;
uint32_t month = time_4g.substring(5,7).toInt();
uint32_t day = time_4g.substring(8,10).toInt();
uint32_t hour = time_4g.substring(11,13).toInt();
uint32_t minute = time_4g.substring(14,16).toInt();
uint32_t second = time_4g.substring(17,-1).toInt();
hour = hour + 8;
if(hour > 23)
{
hour = hour - 24;
day = day + 1;
}
if(now.year != year || now.month != month || now.day != day || now.hour - hour || (fabs(now.minute - minute)>5 ))
{
now.year = year;
now.month = month;
now.day = day;
now.hour = hour;
now.minute = minute;
now.second = second;
rtc.setDateTime(&now);
}
////获取GPS
gps_struct gps_structure;
String gpsbac = get_GPS(&gps_structure);
if(gpsbac == "-1") write_log(log_path,"no gps",10);
else if(gpsbac != "-1")
{
if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS)
{
sun_latitude = gps_structure.latitude;
sun_longitude = gps_structure.longitude;
sys_sd_doc["gps_info"]["latitude"] = sun_latitude;
sys_sd_doc["gps_info"]["longitude"] = sun_longitude;
xSemaphoreGive(xMutexInventory);
}
//Serial.println("gps_structure.latitude " + String(gps_structure.latitude));
//Serial.println("gps_structure.longitude " + String(gps_structure.longitude));
// gps_structure.year = gps_structure.year - 2000;
// if(now.year != gps_structure.year || now.month != gps_structure.month || now.day != gps_structure.day || now.hour != gps_structure.hour || (fabs(now.minute - net_structure.minute)>5 ))
// {
// now.year = gps_structure.year;
// now.month = gps_structure.month;
// now.day = gps_structure.day;
// now.hour = gps_structure.hour;
// now.minute = gps_structure.minute;
// now.second = gps_structure.second;
// // rtc.setDateTime(&now);
// }
// last_day = now.day;
}
}
float now_time = now.hour + now.minute/100;
//Serial.println("now_time " + String(now_time));
//Serial.println("start_time " + String(start_time));
//Serial.println("stop_time " + String(stop_time));
// vTaskDelay(1000 * 1);
float start = 7;
float stop = 19;
if(sys_sd_doc["work_time"] = "gps")
{
start = sunrise;
stop = sunset;
write_log(log_path,"work_time gps",10);
}
else if(sys_sd_doc["work_time"] = "manual")
{
start = start_time;
stop = stop_time;
write_log(log_path,"manual",10);
}
if((now_time >= start) && (now_time < stop))
{
is11Sensor->TakeOneJob();
is11Sensor->get_fanshelv();
if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS)
{
// doc_4G["SN"] = STRSensorInfos_structure.serialnumber;
// doc_4G["latitude"] = sun_latitude;
// doc_4G["longitude"] = sun_longitude;
// doc_4G["Version"] = sys_sd_doc["version"] ;
// doc_4G["a1"] = STRSensorInfos_structure.a1;
// doc_4G["a2"] = STRSensorInfos_structure.a2;
// doc_4G["a3"] = STRSensorInfos_structure.a3;
// doc_4G["a4"] = STRSensorInfos_structure.a4;
// http_head.sn
String sn = STRSensorInfos_structure.serialnumber;
write_log(log_path,"task 4g sn: " + sn,10);
memset(&http_head,'\0',sizeof(http_head));
String version = sys_sd_doc["version"] ;
memcpy(http_head.sn,sn.c_str(),sn.length());
memcpy(http_head.version,version.c_str(),version.length());
http_head.sn[sn.length()] = '\0';
http_head.version[version.length()] = '\0';
// http_head.sn[0] = 'i';
// http_head.sn[1] = 's';
// http_head.sn[2] = '1';
// http_head.sn[3] = '1';
// http_head.sn[4] = '0';
// http_head.sn[5] = '0';
// http_head.sn[6] = '7';
// http_head.sn[7] = '\0';
http_head.lat = sun_latitude;
http_head.lon = sun_longitude;
http_head.is3_a1 = is11Sensor->SensorInfo.a1;
http_head.is3_a2 = is11Sensor->SensorInfo.a2;
http_head.is3_a3 = is11Sensor->SensorInfo.a3;
http_head.is3_a4 = is11Sensor->SensorInfo.a4;
xSemaphoreGive(xMutexInventory);
}
memcpy(data,&http_head,sizeof(http_head));
memcpy((data + sizeof(http_head)),&IS11_datastruct_fanshelv,sizeof(IS11_datastruct_fanshelv));
vTaskDelay(10);
write_log(log_path,"upload data to server",10);
UpdateData("/HyperspectralV2/DataUpload.php",data , sizeof(http_head) + sizeof(IS11_datastruct_fanshelv),HTTP_METHOD_POST);
}
//Serial.println("http_head.lat " + String(http_head.lat));
//Serial.println("http_head.lon " + String(http_head.lon));
vTaskDelay(1000 * time_interval);
}
vTaskDelay(10);
}
if(warn_sta)
{
String data_info;
serializeJson(doc_4G,data_info);
UpdateData("/HyperspectralV2/warning.php",(uint8_t *)data_info.c_str() ,data_info.length() ,HTTP_METHOD_POST);
}
}
@ -1020,10 +957,10 @@ void OTA_task(void *pvParameters)
xEventGroupWaitBits(Main_EventGroup, OTA_BIT, pdTRUE, pdFALSE, portMAX_DELAY);
write_log(log_path,"ota start",10);
vTaskDelay(100);
// vTaskSuspend(Task0_Handler);
// vTaskSuspend(Task1_Handler);
vTaskSuspend(Task0_Handler);
vTaskSuspend(Task1_Handler);
vTaskSuspend(A4G_Handler);
// vTaskSuspend(A4G_Handler);
String url = sys_sd_doc["version_url"];
String MD5 = sys_sd_doc["MD5"];
@ -1353,7 +1290,7 @@ command : 1、get_sensor_info
void json_command(uint8_t port_type)
{
int ret;
bool save = false;
String send_str;
// u_char send_buff[1000];
String json_str;
@ -1512,9 +1449,6 @@ void json_command(uint8_t port_type)
{
save = true;
sys_sd_doc["work_mode"] = "4G_mode";
// sys_sd_doc["caiji_mode"] = "low_power";
// sys_sd_doc["atuo_return"] = "no";
// sys_sd_doc["return_data_type"] = 0x00;
work_mode = 4;
@ -2513,12 +2447,13 @@ void json_command(uint8_t port_type)
// vTaskSuspend(Task2_Handler);
if(sys_sd_doc["status_4g"] == "open_4g")
{
vTaskSuspend(A4G_Handler);
// vTaskSuspend(A4G_Handler);
vTaskSuspend(OTA_Handler);
}
else
{
vTaskSuspend(Task0_Handler);
vTaskSuspend(Task1_Handler);
}
}
@ -2558,17 +2493,17 @@ void json_command(uint8_t port_type)
else if(port_type == 2) mqtt_write(send_buff,ret);
}
//将修改后的系统信息写入内存卡
if(save == true)
{
send_str = "";
serializeJson(sys_sd_doc, send_str);
File file;
file = SD_MMC.open("/system/system_info.json","w+");
file.println(send_str);
file.flush();
file.close();
save = false;
}
// if(save == true)
// {
// send_str = "";
// serializeJson(sys_sd_doc, send_str);
// File file;
// file = SD_MMC.open("/system/system_info.json","w+");
// file.println(send_str);
// file.flush();
// file.close();
// save = false;
// }
xSemaphoreGive(xMutexInventory);
}
@ -2744,9 +2679,9 @@ void sys_info_init()
sys_sd_doc["servo_offset_angle"] = 0;
sys_sd_doc["bochangxishu"]["a0"] = is11Sensor->SensorInfo.a1;
sys_sd_doc["bochangxishu"]["a1"] = is11Sensor->SensorInfo.a1;
sys_sd_doc["bochangxishu"]["a2"] = is11Sensor->SensorInfo.a1;
sys_sd_doc["bochangxishu"]["a3"] = is11Sensor->SensorInfo.a1;
sys_sd_doc["bochangxishu"]["a1"] = is11Sensor->SensorInfo.a2;
sys_sd_doc["bochangxishu"]["a2"] = is11Sensor->SensorInfo.a3;
sys_sd_doc["bochangxishu"]["a3"] = is11Sensor->SensorInfo.a4;
sys_sd_doc["bochangxishu"]["b0"] = 0;
sys_sd_doc["bochangxishu"]["b1"] = 0;