This commit is contained in:
2026-09-23 14:04:22 +08:00
parent f92ced58df
commit 8fd363af5c
4 changed files with 104 additions and 12 deletions

View File

@ -4,7 +4,7 @@
// #define TINY_GSM_MODEM_SIM800 // #define TINY_GSM_MODEM_SIM800
#define TINY_GSM_MODEM_BG96 #define TINY_GSM_MODEM_BG96
#define SerialMon Serial0 #define SerialMon Serial
#include <TinyGsmClient.h> #include <TinyGsmClient.h>
#include <PubSubClient.h> #include <PubSubClient.h>
#include "log.h" #include "log.h"

View File

@ -33,6 +33,21 @@ Ds1302::Ds1302(uint8_t pin_ena, uint8_t pin_clk, uint8_t pin_dat)
} }
void system_tiem_init(struct tm t)
{
// struct tm t;
// t.tm_year = dt->year - 1900;
// t.tm_mon = dt->month - 1;
// t.tm_mday = dt->day;
// t.tm_hour = dt->hour;
// t.tm_min = dt->minute;
// t.tm_sec = dt->second;
time_t sys_now = mktime(&t);
struct timeval tv = { sys_now, 0 };
settimeofday(&tv, nullptr); // 设置系统时间
}
void Ds1302::init() void Ds1302::init()
{ {
pinMode(_pin_ena, OUTPUT); pinMode(_pin_ena, OUTPUT);
@ -41,6 +56,43 @@ void Ds1302::init()
digitalWrite(_pin_ena, LOW); digitalWrite(_pin_ena, LOW);
digitalWrite(_pin_clk, LOW); digitalWrite(_pin_clk, LOW);
Ds1302::DateTime dt;
Ds1302::getDateTime(&dt);
// snprintf(,"init time: %d-%d-%d %d:%d:%d", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
String log = "init time:" + String(dt.year) + "-" + String(dt.month) + "-" + String(dt.day) + " " + String(dt.hour) + ":" + String(dt.minute) + ":" + String(dt.second);
write_log(log_path,log,10);
if(dt.year < (2025 - 2000))
{
dt = {
.year = 26,
.month = 6,
.day = 25,
.hour = 10,
.minute = 0,
.second = 0
// .dow = 1
};
Ds1302::setDateTime(&dt);
}
else
{
struct tm t;
t.tm_year = dt.year - 1900;
t.tm_mon = dt.month - 1;
t.tm_mday = dt.day;
t.tm_hour = dt.hour;
t.tm_min = dt.minute;
t.tm_sec = dt.second;
// time_t sys_now = mktime(&t);
// struct timeval tv = { sys_now, 0 };
// settimeofday(&tv, nullptr); // 设置系统时间
system_tiem_init(t);
}
} }
@ -63,6 +115,8 @@ void Ds1302::getDateTime(DateTime* dt)
dt->month = _bcd2dec(_readByte() & 0b00011111); dt->month = _bcd2dec(_readByte() & 0b00011111);
dt->dow = _bcd2dec(_readByte() & 0b00000111); dt->dow = _bcd2dec(_readByte() & 0b00000111);
dt->year = _bcd2dec(_readByte() & 0b11111111); dt->year = _bcd2dec(_readByte() & 0b11111111);
_end(); _end();
} }
@ -82,6 +136,21 @@ void Ds1302::setDateTime(DateTime* dt)
_writeByte(_dec2bcd(dt->dow % 8 )); _writeByte(_dec2bcd(dt->dow % 8 ));
_writeByte(_dec2bcd(dt->year % 100)); _writeByte(_dec2bcd(dt->year % 100));
_writeByte(0b10000000); _writeByte(0b10000000);
struct tm t;
t.tm_year = dt->year - 1900;
t.tm_mon = dt->month - 1;
t.tm_mday = dt->day;
t.tm_hour = dt->hour;
t.tm_min = dt->minute;
t.tm_sec = dt->second;
// time_t sys_now = mktime(&t);
// struct timeval tv = { sys_now, 0 };
// settimeofday(&tv, nullptr); // 设置系统时间
system_tiem_init(t);
_end(); _end();
} }

View File

@ -13,7 +13,9 @@
#define _DS_1302_H #define _DS_1302_H
#include <stdint.h> #include <stdint.h>
#include <Arduino.h>
#include "time.h"
#include "log.h"
class Ds1302 class Ds1302
{ {
public: public:

View File

@ -130,7 +130,6 @@ size_t serialread(u_char *data, size_t lenth)
int lenthofread = IS1Serial->readBytes(data,lenth); int lenthofread = IS1Serial->readBytes(data,lenth);
return lenthofread; return lenthofread;
} }
////////////////////////////////AIR780EG/////////////////////////////////////////// ////////////////////////////////AIR780EG///////////////////////////////////////////
@ -220,16 +219,27 @@ void setup()
// 初始化DS18b20 // 初始化DS18b20
uint8_t temp_number = DS18b20_init(); uint8_t temp_number = DS18b20_init();
// servo_init(21,0);
// shutter_off();
// int aaaaaa=0;
// while(1) // while(1)
// { // {
// if(aaaaaa == 10) shutter_up();
// if(aaaaaa == 20) shutter_down();
// if(aaaaaa == 30) shutter_on();
// if(aaaaaa == 40) shutter_off();
// if(aaaaaa == 45) aaaaaa = 0;
// ////排序时使用 // ////排序时使用
// float temp[8]; // // float temp[8];
// getall_temp(temp); // // getall_temp(temp);
// // Serial.println("\n");
// for(int i = 0;i<8;i++) // // for(int i = 0;i<8;i++)
// { // // {
// Serial.printf("temp[%d]: %f\n",i + 1,temp[i]); // // Serial.printf("temp[%d]: %f\n",i + 1,temp[i]);
// } // // }
// // Serial.println("\n");
// // vTaskDelay(500);
// aaaaaa ++;
// vTaskDelay(500); // vTaskDelay(500);
// } // }
@ -288,6 +298,11 @@ void setup()
write_log(log_path,"IS_SN :" +STRSensorInfos_structure.serialnumber,20); write_log(log_path,"IS_SN :" +STRSensorInfos_structure.serialnumber,20);
write_log(log_path,"IS_SN :" +String(STRSensorInfos_structure.a1),20);
write_log(log_path,"IS_SN :" +String(STRSensorInfos_structure.a2),20);
write_log(log_path,"IS_SN :" +String(STRSensorInfos_structure.a3),20);
write_log(log_path,"IS_SN :" +String(STRSensorInfos_structure.a4),20);
write_log(log_path,"IS_SN :" +String(STRSensorInfos_structure.BandNum),20);
// is11Sensor->guangpu_bochang.a1 = 0.000000000000000; // is11Sensor->guangpu_bochang.a1 = 0.000000000000000;
// is11Sensor->guangpu_bochang.a2 = 0.000000000; // is11Sensor->guangpu_bochang.a2 = 0.000000000;
@ -828,7 +843,6 @@ void Task2(void *pvParameters)
save = false; save = false;
xSemaphoreGive(xMutexInventory); xSemaphoreGive(xMutexInventory);
} }
} }
} }
} }
@ -1128,6 +1142,13 @@ void receive_command_unpack(uint8_t * read_buf,uint16_t data_length,uint8_t port
data[2] = STRSensorInfos_structure.a3; data[2] = STRSensorInfos_structure.a3;
data[3] = STRSensorInfos_structure.a4; data[3] = STRSensorInfos_structure.a4;
// data[0] = is11Sensor->guangpu_bochang.a0;
// data[1] = is11Sensor->guangpu_bochang.a1;
// data[2] = is11Sensor->guangpu_bochang.a2;
// data[3] = is11Sensor->guangpu_bochang.a3;
send_lenth = IRIS_Protocol_Pack(0x61,16,(uint8_t *)data,send_buff); send_lenth = IRIS_Protocol_Pack(0x61,16,(uint8_t *)data,send_buff);