mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
due OTA programming, EEPROM signature check
This commit is contained in:
BIN
compiled/due/firmware.bin
Executable file
BIN
compiled/due/firmware.bin
Executable file
Binary file not shown.
1
compiled/due/uploadOTA.sh
Executable file
1
compiled/due/uploadOTA.sh
Executable file
@@ -0,0 +1 @@
|
||||
../tools/mac/arduinoOTA -address 192.168.8.56 -port 65280 -username arduino -password password -sketch firmware.bin -b -upload /sketch
|
||||
BIN
compiled/tools/mac/arduinoOTA
Executable file
BIN
compiled/tools/mac/arduinoOTA
Executable file
Binary file not shown.
@@ -1,3 +1,4 @@
|
||||
cp ../.pio/build/due/firmware.bin due
|
||||
cp ../.pio/build/controllino/firmware.hex controllino
|
||||
cp ../.pio/build/m5stack/firmware.bin m5stack
|
||||
cp ../.pio/build/mega2560slim-5100/firmware.hex mega2560slim-5100
|
||||
|
||||
@@ -66,7 +66,7 @@ PWM Out
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#include <Dhcp.h>
|
||||
#if defined(OTA)
|
||||
#include <ArduinoOTA.h>
|
||||
#endif
|
||||
@@ -406,16 +406,6 @@ if (WiFi.status() != WL_CONNECTED)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef wiz5500
|
||||
|
||||
#define DHCP_CHECK_RENEW_FAIL 1
|
||||
#define DHCP_CHECK_RENEW_OK 2
|
||||
#define DHCP_CHECK_REBIND_FAIL 3
|
||||
#define DHCP_CHECK_REBIND_OK 4
|
||||
#define NO_LINK 5
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__) || defined (NRF5)
|
||||
wdt_dis();
|
||||
@@ -423,9 +413,11 @@ if (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
int etherStatus = Ethernet.maintain();
|
||||
|
||||
#ifdef ETHENET_GENERIC
|
||||
#ifndef Wiz5500
|
||||
#define NO_LINK 5
|
||||
if (Ethernet.linkStatus() == LinkOFF) etherStatus = NO_LINK;
|
||||
#endif
|
||||
|
||||
switch (etherStatus) {
|
||||
case NO_LINK:
|
||||
debugSerial<<F("No link")<<endl;
|
||||
@@ -1091,9 +1083,9 @@ int loadConfigFromEEPROM()
|
||||
char ch;
|
||||
debugSerial<<F("Loading Config from EEPROM")<<endl;
|
||||
|
||||
ch = EEPROM.read(EEPROM_offset);
|
||||
ch = EEPROM.read(EEPROM_offsetJSON);
|
||||
if (ch == '{') {
|
||||
aJsonEEPROMStream as = aJsonEEPROMStream(EEPROM_offset);
|
||||
aJsonEEPROMStream as = aJsonEEPROMStream(EEPROM_offsetJSON);
|
||||
cleanConf();
|
||||
root = aJson.parse(&as);
|
||||
if (!root) {
|
||||
@@ -1162,7 +1154,7 @@ void cmdFunctionSave(int arg_cnt, char **args)
|
||||
aJson.print(root, &stringStream);
|
||||
int len = strlen(outBuf);
|
||||
outBuf[len++]= EOF;
|
||||
EEPROM.write(EEPROM_offset,(byte*) outBuf,len);
|
||||
EEPROM.write(EEPROM_offsetJSON,(byte*) outBuf,len);
|
||||
|
||||
free (outBuf);
|
||||
debugSerial<<F("Saved to EEPROM");
|
||||
@@ -1171,7 +1163,7 @@ void cmdFunctionSave(int arg_cnt, char **args)
|
||||
#else
|
||||
void cmdFunctionSave(int arg_cnt, char **args)
|
||||
{
|
||||
aJsonEEPROMStream jsonEEPROMStream = aJsonEEPROMStream(EEPROM_offset);
|
||||
aJsonEEPROMStream jsonEEPROMStream = aJsonEEPROMStream(EEPROM_offsetJSON);
|
||||
debugSerial<<F("Saving config to EEPROM..");
|
||||
|
||||
aJson.print(root, &jsonEEPROMStream);
|
||||
@@ -1236,8 +1228,12 @@ void cmdFunctionIp(int arg_cnt, char **args)
|
||||
}
|
||||
|
||||
void cmdFunctionClearEEPROM(int arg_cnt, char **args){
|
||||
for (int i = 0; i < 512; i++)
|
||||
for (int i = OFFSET_MAC; i < OFFSET_MAC+EEPROM_FIX_PART_LEN; i++)
|
||||
EEPROM.write(i, 0);
|
||||
|
||||
for (int i = 0; i < sizeof(EEPROM_signature); i++)
|
||||
EEPROM.write(i+OFFSET_SIGNATURE,EEPROM_signature[i]);
|
||||
|
||||
debugSerial<<F("EEPROM cleared\n");
|
||||
|
||||
}
|
||||
@@ -1486,8 +1482,9 @@ void postTransmission() {
|
||||
}
|
||||
|
||||
void setup_main() {
|
||||
//Serial.println("Hello");
|
||||
//delay(1000);
|
||||
|
||||
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
memset(&UniqueID,0,sizeof(UniqueID));
|
||||
#endif
|
||||
@@ -1500,6 +1497,13 @@ void setup_main() {
|
||||
setupCmdArduino();
|
||||
printFirmwareVersionAndBuildOptions();
|
||||
|
||||
//Checkin EEPROM integrity (signature)
|
||||
for (int i=OFFSET_SIGNATURE;i<OFFSET_SIGNATURE+sizeof(EEPROM_SIGNATURE);i++)
|
||||
if (EEPROM.read(i)!=EEPROM_signature[i])
|
||||
{
|
||||
cmdFunctionClearEEPROM(0,NULL);
|
||||
break;
|
||||
}
|
||||
// scan_i2c_bus();
|
||||
|
||||
#ifdef SD_CARD_INSERTED
|
||||
@@ -1581,6 +1585,8 @@ void printFirmwareVersionAndBuildOptions() {
|
||||
|
||||
#ifdef Wiz5500
|
||||
debugSerial<<F("\n(+)WizNet5500");
|
||||
#else
|
||||
debugSerial<<F("\n(+)Wiznet5x00");
|
||||
#endif
|
||||
|
||||
#ifndef DMX_DISABLE
|
||||
|
||||
@@ -47,8 +47,11 @@
|
||||
#define OFFSET_MASK OFFSET_GW+4
|
||||
#define OFFSET_CONFIGSERVER OFFSET_MASK+4
|
||||
#define OFFSET_MQTT_PWD OFFSET_CONFIGSERVER+MAXFLASHSTR
|
||||
#define EEPROM_offset_NotAlligned OFFSET_MQTT_PWD+PWDFLASHSTR
|
||||
#define EEPROM_offset EEPROM_offset_NotAlligned + (4 -(EEPROM_offset_NotAlligned & 3))
|
||||
#define OFFSET_SIGNATURE OFFSET_MQTT_PWD+PWDFLASHSTR
|
||||
#define EEPROM_offset_NotAlligned OFFSET_SIGNATURE+4
|
||||
#define EEPROM_offsetJSON EEPROM_offset_NotAlligned + (4 -(EEPROM_offset_NotAlligned & 3))
|
||||
#define EEPROM_FIX_PART_LEN EEPROM_offsetJSON-OFFSET_MAC
|
||||
#define EEPROM_SIGNATURE "LHCF"
|
||||
|
||||
#ifndef INTERVAL_CHECK_INPUT
|
||||
#define INTERVAL_CHECK_INPUT 15
|
||||
|
||||
@@ -116,3 +116,4 @@ const char RGB_P[] PROGMEM = "RGB";
|
||||
const char RPM_P[] PROGMEM = "rpm";
|
||||
const char STATE_P[] PROGMEM = "state";
|
||||
*/
|
||||
const char EEPROM_signature[] = EEPROM_SIGNATURE;
|
||||
|
||||
@@ -291,7 +291,7 @@ lib_deps =
|
||||
https://github.com/anklimov/aJson
|
||||
https://github.com/anklimov/CmdArduino
|
||||
https://github.com/anklimov/ModbusMaster
|
||||
https://github.com/arduino-libraries/Ethernet.git
|
||||
https://github.com/anklimov/Ethernet.git
|
||||
;https://github.com/anklimov/Ethernet2.git
|
||||
https://github.com/knolleary/pubsubclient.git
|
||||
https://github.com/anklimov/Artnet.git
|
||||
|
||||
Reference in New Issue
Block a user