Minor fixes
This commit is contained in:
parent
e3d3054a92
commit
5ecfd2a3b4
|
@ -47,11 +47,15 @@
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#define Debug(x) Serial1.print(x)
|
#define Debug(x) Serial1.print(x)
|
||||||
#define Debugln(x) Serial1.println(x)
|
#define Debugln(x) Serial1.println(x)
|
||||||
|
#define DebugF(x) Serial1.print(F(x))
|
||||||
|
#define DebuglnF(x) Serial1.println(F(x))
|
||||||
#define Debugf(...) Serial1.printf(__VA_ARGS__)
|
#define Debugf(...) Serial1.printf(__VA_ARGS__)
|
||||||
#define Debugflush Serial1.flush
|
#define Debugflush Serial1.flush
|
||||||
#else
|
#else
|
||||||
#define Debug(x) {}
|
#define Debug(x) {}
|
||||||
#define Debugln(x) {}
|
#define Debugln(x) {}
|
||||||
|
#define DebugF(x) {}
|
||||||
|
#define DebuglnF(x) {}
|
||||||
#define Debugf(...) {}
|
#define Debugf(...) {}
|
||||||
#define Debugflush {}
|
#define Debugflush {}
|
||||||
#endif
|
#endif
|
||||||
|
@ -62,6 +66,7 @@
|
||||||
#define RED_LED_PIN 12
|
#define RED_LED_PIN 12
|
||||||
// value for RGB color
|
// value for RGB color
|
||||||
#define COLOR_RED rgb_brightness, 0, 0
|
#define COLOR_RED rgb_brightness, 0, 0
|
||||||
|
#define COLOR_ORANGE rgb_brightness, rgb_brightness>>1, 0
|
||||||
#define COLOR_YELLOW rgb_brightness, rgb_brightness, 0
|
#define COLOR_YELLOW rgb_brightness, rgb_brightness, 0
|
||||||
#define COLOR_GREEN 0, rgb_brightness, 0
|
#define COLOR_GREEN 0, rgb_brightness, 0
|
||||||
#define COLOR_CYAN 0, rgb_brightness, rgb_brightness
|
#define COLOR_CYAN 0, rgb_brightness, rgb_brightness
|
||||||
|
|
|
@ -88,7 +88,7 @@ void UpdateSysinfo(boolean first_call, boolean show_debug)
|
||||||
|
|
||||||
// Values not subject to change during running sketch
|
// Values not subject to change during running sketch
|
||||||
if (first_call) {
|
if (first_call) {
|
||||||
sprintf( buff, "%d KB", ESP.getFlashChipSize()/1024 );
|
sprintf( buff, "%d KB", ESP.getFlashChipRealSize()/1024 );
|
||||||
sysinfo.sys_flash_size = buff;
|
sysinfo.sys_flash_size = buff;
|
||||||
sprintf( buff, "%d KB", ESP.getSketchSize()/1024 );
|
sprintf( buff, "%d KB", ESP.getSketchSize()/1024 );
|
||||||
sysinfo.sys_firmware_size = buff;
|
sysinfo.sys_firmware_size = buff;
|
||||||
|
@ -98,9 +98,9 @@ void UpdateSysinfo(boolean first_call, boolean show_debug)
|
||||||
sysinfo.sys_flash_speed = buff;
|
sysinfo.sys_flash_speed = buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (show_debug)
|
if (show_debug) {
|
||||||
{
|
|
||||||
Debug(F("Firmware : ")); Debugln(__DATE__ " " __TIME__);
|
Debug(F("Firmware : ")); Debugln(__DATE__ " " __TIME__);
|
||||||
|
Debug(F("Flash real id: ")); Serial1.printf("0x%08X\r\n", ESP.getFlashChipId());
|
||||||
Debug(F("Flash Size : ")); Debugln(sysinfo.sys_flash_size);
|
Debug(F("Flash Size : ")); Debugln(sysinfo.sys_flash_size);
|
||||||
Debug(F("CPU Speed : ")); Debugln(sysinfo.sys_flash_speed);
|
Debug(F("CPU Speed : ")); Debugln(sysinfo.sys_flash_speed);
|
||||||
Debug(F("Sketch size : ")); Debugln(sysinfo.sys_firmware_size);
|
Debug(F("Sketch size : ")); Debugln(sysinfo.sys_firmware_size);
|
||||||
|
@ -267,68 +267,52 @@ void CheckOTAUpdate(void)
|
||||||
int port = OTA.parseInt();
|
int port = OTA.parseInt();
|
||||||
int size = OTA.parseInt();
|
int size = OTA.parseInt();
|
||||||
|
|
||||||
Debug(F("Update Start: ip:"));
|
LedRGBON(COLOR_MAGENTA);
|
||||||
|
|
||||||
|
DebugF("Update Start: ip:");
|
||||||
Debug(remote);
|
Debug(remote);
|
||||||
Debugf(", port:%d, size:%d\n", port, size);
|
Debugf(", port:%d, size:%dKB\n", port, size/1024);
|
||||||
uint32_t startTime = millis();
|
uint32_t startTime = millis();
|
||||||
|
|
||||||
WiFiUDP::stopAll();
|
WiFiUDP::stopAll();
|
||||||
|
|
||||||
for (uint8_t i=0; i<=10;i++) {
|
if(!Update.begin(size)) {
|
||||||
LedRGBOFF();
|
DebugF("Update Begin Error");
|
||||||
delay(75);
|
|
||||||
LedRGBON(COLOR_MAGENTA);
|
|
||||||
delay(25);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ww = 0;
|
|
||||||
WiFiClient client;
|
|
||||||
|
|
||||||
if (!client.connect(remote, port)){
|
|
||||||
Debugf("Connect Failed: %u\n", millis() - startTime);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
client.setTimeout(10000);
|
WiFiClient ota_client;
|
||||||
int cntr = 0;
|
|
||||||
int z = 0;
|
|
||||||
uint16_t crc;
|
|
||||||
|
|
||||||
// do until we do not get transfered full size
|
if (ota_client.connect(remote, port)) {
|
||||||
while (cntr<size) {
|
|
||||||
z = 0;
|
|
||||||
crc = 0;
|
|
||||||
for(int i=client.available();i>0;i--) {
|
|
||||||
int b = client.read();
|
|
||||||
|
|
||||||
// timeout
|
uint32_t written;
|
||||||
if (b == -1)
|
while(!Update.isFinished()) {
|
||||||
break;
|
written = Update.write(ota_client);
|
||||||
|
if(written > 0)
|
||||||
crc += (byte)b;
|
{
|
||||||
z++;
|
LedRGBOFF();
|
||||||
cntr++;
|
ota_client.print(written, DEC);
|
||||||
|
LedRGBON(COLOR_MAGENTA);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Printback code differ from original espota.py
|
|
||||||
if (z)
|
|
||||||
client.printf(PSTR("%d %d\n"), z, crc);
|
|
||||||
}
|
}
|
||||||
Debugf("Done %d/%d\r\n", cntr, size);
|
LedRGBOFF();
|
||||||
|
Serial.setDebugOutput(false);
|
||||||
|
|
||||||
// All transfered ?
|
if(Update.end()) {
|
||||||
if(cntr>=size) {
|
ota_client.println("OK");
|
||||||
client.print("OK");
|
Debugf("Update Success: %u\nRebooting...\n", millis() - startTime);
|
||||||
Debugf("Update Success in %u ms\r\nRebooting...\r\n", millis() - startTime);
|
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
} else {
|
} else {
|
||||||
Update.printError(client);
|
Update.printError(ota_client);
|
||||||
Update.printError(Serial1);
|
Update.printError(Serial);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Debugf("Connect Failed: %u\n", millis() - startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Be sure to re enable it
|
// Be sure to re enable it
|
||||||
OTA.begin(config.ota_port);
|
OTA.begin(DEFAULT_OTA_PORT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ======================================================================
|
/* ======================================================================
|
||||||
|
@ -344,37 +328,40 @@ int WifiHandleConn()
|
||||||
|
|
||||||
// Wait for connection if disconnected
|
// Wait for connection if disconnected
|
||||||
if ( ret != WL_CONNECTED ) {
|
if ( ret != WL_CONNECTED ) {
|
||||||
// Yellow we're not connected anymore
|
|
||||||
LedRGBON(COLOR_YELLOW);
|
|
||||||
|
|
||||||
Debug(F("Connecting to: "));
|
// Orange we're not connected anymore
|
||||||
Debug( config.ssid );
|
LedRGBON(COLOR_ORANGE);
|
||||||
|
|
||||||
|
DebugF("Connecting to: ");
|
||||||
|
Debug(DEFAULT_WIFI_SSID);
|
||||||
Debug(F("..."));
|
Debug(F("..."));
|
||||||
|
|
||||||
WiFi.begin(config.ssid, config.pass);
|
WiFi.begin(DEFAULT_WIFI_SSID, DEFAULT_WIFI_PASS);
|
||||||
|
|
||||||
ret = WiFi.waitForConnectResult();
|
ret = WiFi.waitForConnectResult();
|
||||||
if ( ret != WL_CONNECTED) {
|
if ( ret != WL_CONNECTED) {
|
||||||
Debugln(F("Connection failed!"));
|
LedRGBON(COLOR_RED);
|
||||||
|
DebuglnF("Connection failed!");
|
||||||
} else {
|
} else {
|
||||||
Debugln(F("Connected"));
|
LedRGBON(COLOR_GREEN);
|
||||||
Debug(F("IP address : ")); Debugln(WiFi.localIP());
|
DebuglnF("Connected");
|
||||||
Debug(F("MAC address : ")); Debugln(WiFi.macAddress());
|
DebugF("IP address : "); Debugln(WiFi.localIP());
|
||||||
|
DebugF("MAC address : "); Debugln(WiFi.macAddress());
|
||||||
|
|
||||||
MDNS.begin(config.host);
|
MDNS.begin(DEFAULT_HOSTNAME);
|
||||||
MDNS.addService("arduino", "tcp", config.ota_port);
|
MDNS.addService("arduino", "tcp", DEFAULT_OTA_PORT);
|
||||||
OTA.begin(config.ota_port);
|
OTA.begin(DEFAULT_OTA_PORT);
|
||||||
|
|
||||||
// just in case your sketch sucks, keep update OTA Available
|
// just in case your sketch sucks, keep update OTA Available
|
||||||
// Trust me, when coding and testing it happens, this could save
|
// Trust me, when coding and testing it happens, this could save
|
||||||
// the need to connect FTDI to reflash
|
// the need to connect FTDI to reflash
|
||||||
// Usefull just after 1st connexion when called from setup() before
|
// Usefull just after 1st connexion when called from setup() before
|
||||||
// launching potentially bugging main()
|
// launching potentially bugging main()
|
||||||
for (uint8_t i=0; i<= 20; i++) {
|
for (uint8_t i=0; i<= 10; i++) {
|
||||||
LedRGBON(COLOR_GREEN);
|
LedRGBON(COLOR_MAGENTA);
|
||||||
delay(25);
|
delay(100);
|
||||||
LedRGBOFF();
|
LedRGBOFF();
|
||||||
delay(75);
|
delay(200);
|
||||||
CheckOTAUpdate();
|
CheckOTAUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -396,11 +383,17 @@ Comments: -
|
||||||
====================================================================== */
|
====================================================================== */
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
boolean reset_config = true;
|
||||||
|
|
||||||
// Set WiFi to station mode and disconnect from an AP if it was previously connected
|
// Set WiFi to station mode and disconnect from an AP if it was previously connected
|
||||||
//WiFi.mode(WIFI_STA);
|
//WiFi.mode(WIFI_STA);
|
||||||
//WiFi.disconnect();
|
//WiFi.disconnect();
|
||||||
//delay(100);
|
//delay(100);
|
||||||
|
|
||||||
|
// Init the RGB Led, and set it off
|
||||||
|
rgb_led.Begin();
|
||||||
|
LedRGBOFF();
|
||||||
|
|
||||||
// Init the serial 1
|
// Init the serial 1
|
||||||
// Teleinfo is connected to RXD2 (GPIO13) to
|
// Teleinfo is connected to RXD2 (GPIO13) to
|
||||||
// avoid conflict when flashing, this is why
|
// avoid conflict when flashing, this is why
|
||||||
|
@ -427,8 +420,16 @@ void setup()
|
||||||
|
|
||||||
// Read Configuration from EEP
|
// Read Configuration from EEP
|
||||||
if (readConfig()) {
|
if (readConfig()) {
|
||||||
sysinfo.sys_eep_config = PSTR("good CRC, config OK");
|
// in case of saved default config it's not good
|
||||||
|
if (config.ssid[0]!='*' && config.pass[0]!='*' ) {
|
||||||
|
sysinfo.sys_eep_config = PSTR("Good CRC, config OK");
|
||||||
|
reset_config = false;
|
||||||
} else {
|
} else {
|
||||||
|
sysinfo.sys_eep_config = PSTR("Good CRC, not set!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reset_config ) {
|
||||||
// Error, enable default configuration
|
// Error, enable default configuration
|
||||||
strcpy_P(config.ssid, PSTR(DEFAULT_WIFI_SSID));
|
strcpy_P(config.ssid, PSTR(DEFAULT_WIFI_SSID));
|
||||||
strcpy_P(config.pass, PSTR(DEFAULT_WIFI_PASS));
|
strcpy_P(config.pass, PSTR(DEFAULT_WIFI_PASS));
|
||||||
|
@ -437,7 +438,7 @@ void setup()
|
||||||
|
|
||||||
// Indicate the error in global flags
|
// Indicate the error in global flags
|
||||||
config.config |= CFG_BAD_CRC;
|
config.config |= CFG_BAD_CRC;
|
||||||
sysinfo.sys_eep_config = PSTR("Bad CRC, reset to default");
|
sysinfo.sys_eep_config = PSTR("Reset to default");
|
||||||
|
|
||||||
// save back
|
// save back
|
||||||
saveConfig();
|
saveConfig();
|
||||||
|
@ -455,9 +456,6 @@ void setup()
|
||||||
tinfo.attachNewFrame(NewFrame);
|
tinfo.attachNewFrame(NewFrame);
|
||||||
tinfo.attachUpdatedFrame(UpdatedFrame);
|
tinfo.attachUpdatedFrame(UpdatedFrame);
|
||||||
|
|
||||||
// Init the RGB Led
|
|
||||||
rgb_led.Begin();
|
|
||||||
|
|
||||||
// We'll drive the on board LED (TXD1) and our on GPIO1
|
// We'll drive the on board LED (TXD1) and our on GPIO1
|
||||||
// old TXD1, not used anymore, has been swapped
|
// old TXD1, not used anymore, has been swapped
|
||||||
pinMode(BLU_LED_PIN, OUTPUT);
|
pinMode(BLU_LED_PIN, OUTPUT);
|
||||||
|
|
Loading…
Reference in New Issue