Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTA rBoot v. #2105

Open
kpishere opened this issue Aug 26, 2020 · 6 comments
Open

OTA rBoot v. #2105

kpishere opened this issue Aug 26, 2020 · 6 comments

Comments

@kpishere
Copy link

kpishere commented Aug 26, 2020

I have a project with MQTT client and am attempting to use rBoot also. Config file is thus :

ARDUINO_LIBRARIES 	:= ArduinoJson6
COMPONENT_DEPENDS += spiffs
#COMPONENT_DEPENDS += FlashString

## use rboot build mode
RBOOT_ENABLED		?= 1
## address of ROM slots 0 & 1
RBOOT_ROM0_ADDR 	?= 0x002000
RBOOT_ROM1_ADDR 	?= 0x102000

DISABLE_SPIFFS=0
SPIFF_SIZE      ?= 262144
SPI_SIZE=4M
SPI_MODE=dio
COM_PORT_ESPTOOL=/dev/cu.wchusbserial1470
COM_PORT=/dev/cu.wchusbserial1470
COM_SPEED_ESPTOOL=115200

ESP8266=1
MQTT_URL="mqtt://192.168.1.104:1883"

Upon publishing URL to a topic, the MQTT calls :

  if(topic == _F(MQTT_OTA_ROM_SPIFFS)) {
    int space = message.indexOf(' ');
    if(space>0) {
      String romUrl = message.substring(0,space);
      String spiffUrl = message.substring(space+1);

      irReceiver->listenStop();  // don't want these HW interrupts happening
      disp->listenStop();
      procTimer.stop(); // stop timer event on disconnected mqtt
      mqtt.unsubscribe(_F(MQTT_CONTROL_PATH));
      mqtt.unsubscribe(_F(MQTT_OTA_ROM_SPIFFS));
      mqtt.setKeepAlive(9999); // disable this

      OtaUpdate(romUrl, spiffUrl);
    }

The ota functions are lifted from the basic sample :

/// BEGIN OTA
//
RbootHttpUpdater* otaUpdater = 0;

void OtaUpdate_CallBack(RbootHttpUpdater& client, bool result)
{
	Serial.println("In callback...");
	if(result == true) {
		// success
		uint8 slot;
		slot = rboot_get_current_rom();
		if(slot == 0)
			slot = 1;
		else
			slot = 0;
		// set to boot new rom and then reboot
		Serial.printf("Firmware updated, rebooting to rom %d...\r\n", slot);
		rboot_set_current_rom(slot);
		System.restart();
	} else {
		// fail
		Serial.println("Firmware update failed!");
	}
}

void OtaUpdate(String romUrl, String spiffsUrl)
{
	uint8 slot;
	rboot_config bootconf;

#ifdef DEBUG
	Serial.printf("Updating...\n");
#endif

	// need a clean object, otherwise if run before and failed will not run again
	if(otaUpdater)
		delete otaUpdater;
	otaUpdater = new RbootHttpUpdater();

	// select rom slot to flash
	bootconf = rboot_get_config();
	slot = bootconf.current_rom;
	if(slot == 0)
		slot = 1;
	else
		slot = 0;

	otaUpdater->addItem(bootconf.roms[slot], romUrl);

	// use user supplied values (defaults for 4mb flash in makefile)
	if(slot == 0) {
		otaUpdater->addItem(RBOOT_SPIFFS_0, spiffsUrl);
	} else {
		otaUpdater->addItem(RBOOT_SPIFFS_1, spiffsUrl);
	}

	// request switch and reboot on success
	//otaUpdater->switchToRom(slot);
	// and/or set a callback (called on failure or success without switching requested)
	otaUpdater->setCallback(OtaUpdate_CallBack);

	// start update
	otaUpdater->start();
}
//
/// END OTA

when monitoring the python http server, only rthe following request is made (it completes as per monitoring with wireshark) :

192.168.1.101 - - [26/Aug/2020 00:36:49] "GET /rom0.bin HTTP/1.1" 200 -

Notice that there is no second call to the file spiff_rom.bin as the message to mqtt is :

mosquitto_pub -t hvac/heatpump/ota/rom_spiff -m "http://192.168.1.104:9999/rom0.bin http://192.168.1.104:9999/spiff_rom.bin"

and that the callback OtaUpdate_CallBack never gets executed.

When I attempt to execute the OTA update a second time, the system crashes. Here is the crash report from the dump :

Am I doing something wrong?

3ffffa60:  3fff2c7c 00000000 3fff2b58 3fff0b3c  
3ffffa70:  3fff2c7c 3fff2f58 3fff2f58 4024501c  
3ffffa80:  3fff2c7c 3fff2f58 3fff2b58 40245e44  
3ffffa90:  3fff2d88 00000000 3fff2b58 40245e7f  
3ffffaa0:  4023b9e6 00000000 3fff28f0 40245177  
3ffffab0:  3fff2d88 00000000 3fff28f0 40245245  
3ffffac0:  3fff0b3c 00000000 00000000 00000000  
3ffffad0:  3fff2f08 00000012 00000012 40243f41  
3ffffae0:  00000000 00000000 00000000 40243ddf  
3ffffaf0:  3fff2ab0 3fff2660 3fff2790 3fff2d88  
3ffffb00:  00000000 3fff2660 3fff2790 402445ff  
3ffffb10:  3fff2910 00000000 40243da4 4024b074  
3ffffb20:  00000000 00000000 00000000 00000000  
3ffffb30:  00000000 00000000 00000000 00000000  
3ffffb40:  00001f40 00000000 00000000 00000000  
3ffffb50:  402122e0 00000000 00000000 00000000  
3ffffb60:  00000000 00000000 00000000 00000000  
3ffffb70:  00000000 00000000 00000000 00000009  
3ffffb80:  00000000 3fff2a08 3ffffba0 3ffffcc4  
3ffffb90:  00000000 3fff2794 00082000 00000000  
3ffffba0:  3fff2ec0 00000x4024501c: HttpRequest::~HttpRequest() at /opt/Sming/Sming/Core/Network/HttpClient.cpp:66
 (inlined by) ~Delegate at /opt/Sming/Sming/Core/Delegate.h:25
 (inlined by) HttpRequest::~HttpRequest() at /opt/Sming/Sming/Core/Network/Http/HttpRequest.h:77
0x40245e44: HttpClientConnection::~HttpClientConnection() at /opt/Sming/Sming/Wiring/Countable.h:23
0x40245e7f: HttpClientConnection::~HttpClientConnection() at /opt/Sming/Sming/Wiring/Countable.h:23
0x4023b9e6: String::invalidate() at /opt/Sming/Sming/Wiring/WString.cpp:823 (discriminator 3)
0x40245177: ObjectMap<String, HttpClientConnection>::Entry::~Entry() at /opt/Sming/Sming/Core/Network/HttpClient.cpp:66
 (inlined by) ObjectMap<String, HttpClientConnection>::Entry::~Entry() at /opt/Sming/Sming/Core/Data/ObjectMap.h:333
0x40245245: Vector<ObjectMap<String, HttpClientConnection>::Entry>::removeElementAt(unsigned int) at /opt/Sming/Sming/Core/Network/HttpClient.cpp:66
 (inlined by) Vector<ObjectMap<String, HttpClientConnection>::Entry>::remove(unsigned int) at /opt/Sming/Sming/Wiring/WVector.h:316
 (inlined by) ObjectMap<String, HttpClientConnection>::removeAt(unsigned int) at /opt/Sming/Sming/Core/Data/ObjectMap.h:262
 (inlined by) HttpClient::send(HttpRequest*) at /opt/Sming/Sming/Core/Network/HttpClient.cpp:31
0x40243f41: std::function<int (HttpConnection&, bool)>::operator=(std::function<int (HttpConnection&, bool)> const&) at /opt/Sming/Sming/Wiring/WHashMap.h:329
0x40243ddf: std::_Function_base::_Base_manager<Delegate<int (HttpConnection&, bool)>::Delegate<RbootHttpUpdater>(int (RbootHttpUpdater::*)(HttpConnection&, bool), RbootHttpUpdater*)::{lambda(HttpConnection&, bool)#1}>::_M_manager(std::_Any_data&, std::_Function_base::_Base_manager<Delegate<int (HttpConnection&, bool)>::Delegate<RbootHttpUpdater>(int (RbootHttpUpdater::*)(HttpConnection&, bool), RbootHttpUpdater*)::{lambda(HttpConnection&, bool)#1}> const&, std::_Manager_operation) at /opt/Sming/Sming/Wiring/WHashMap.h:329
0x402445ff: RbootHttpUpdater::start() at /opt/Sming/Sming/Components/rboot/src/RbootHttpUpdater.cpp:75
0x40243da4: std::_Function_base::_Base_manager<Delegate<int (HttpConnection&, bool)>::Delegate<RbootHttpUpdater>(int (RbootHttpUpdater::*)(HttpConnection&, bool), RbootHttpUpdater*)::{lambda(HttpConnection&, bool)#1}>::_M_manager(std::_Any_data&, std::_Function_base::_Base_manager<Delegate<int (HttpConnection&, bool)>::Delegate<RbootHttpUpdater>(int (RbootHttpUpdater::*)(HttpConnection&, bool), RbootHttpUpdater*)::{lambda(HttpConnection&, bool)#1}> const&, std::_Manager_operation) at /opt/Sming/Sming/Wiring/WHashMap.h:329
0x4024b074: std::_Function_base::_Base_manager<Delegate<int (HttpConnection&, bool)>::Delegate<RbootHttpUpdater>(int (RbootHttpUpdater::*)(HttpConnection&, bool), RbootHttpUpdater*)::{lambda(HttpConnection&, bool)#1}>::_M_get_pointer(std::_Any_data const&) at /opt/esp-open-sdk/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.5/functional:1893
 (inlined by) std::_Function_handler<int (HttpConnection&, bool), Delegate<int (HttpConnection&, bool)>::Delegate<RbootHttpUpdater>(int (RbootHttpUpdater::*)(HttpConnection&, bool), RbootHttpUpdater*)::{lambda(HttpConnection&, bool)#1}>::_M_invoke(std::_Any_data const&, HttpConnection&, bool) at /opt/esp-open-sdk/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.5/functional:2056
0x402122e0: wpa_sm_disassociate at ??:?
0000  
3ffffbb0:  00000000 00000000 3fff2790 3ffffcc4  
3ffffbc0:  3ffffcb8 3ffef594 3fff2790 40234a9a  
3ffffbd0:  000001e1 00000200 00002000 00082000  
3ffffbe0:  00000000 00000000 00000000 00000000  
3ffffbf0:  00000000 00000000 40233834 402419ba  
3ffffc00:  4024a578 4024a560 40233834 4010183a  
3ffffc10:  4024a578 4024a560 3ffffcb8 4023bc19  
3ffffc20:  00000000 3fff26c8 3ffffcb8 4023be94  
3ffffc30:  4023b9e6 00000022 3ffef5d4 3ffef7a4  
3ffffc40:  3fff0010 00000022 3ffef5d4 40234c40  
3ffffc50:  63617668 6165682f 6d757074 746f2f70  
3ffffc60:  6f722f61 70735f6d 00666669 63617668  
3ffffc70:  6165682f 6d757074 746f2f70 6f722f61  
3ffffc80:  70735f6d 00666669 63617668 6165682f  
3ffffc90:  6d757074 6f632f70 6f72746e 0000006c  
3ffffca0:  63617668 6165682f 6d757074 6f632f70  
3ffffcb0:  6f72746e 0000006c 3fff2a08 00000027  
3ffffcc0:  00000027 3fff29d0 00000022 00000022  
3ffffcd0:  3fff26c8 00000027 00000027 3fff2690  
3ffffce0:  00000022 00000022 3ffffd58 3ffe0x40234a9a: OtaUpdate(String, String) at /Users/kevinpeck/Documents/Arduino/homie_heatPump/sming_heatpump/app/application.cpp:141
0x40233834: OtaUpdate_CallBack(RbootHttpUpdater&, bool) at /Users/kevinpeck/Documents/Arduino/homie_heatPump/sming_heatpump/app/application.cpp:165
0x402419ba: std::function<void ()>::operator=(std::function<void ()>&&) at /opt/Sming/Sming/Arch/Esp8266/Core/Interrupts.cpp:112
0x4024a578: std::_Function_base::_Base_manager<void (*)(RbootHttpUpdater&, bool)>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) at /opt/esp-open-sdk/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.5/functional:1934
0x4024a560: std::_Function_handler<void (RbootHttpUpdater&, bool), void (*)(RbootHttpUpdater&, bool)>::_M_invoke(std::_Any_data const&, RbootHttpUpdater&, bool) at /opt/esp-open-sdk/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.5/functional:2069
0x40233834: OtaUpdate_CallBack(RbootHttpUpdater&, bool) at /Users/kevinpeck/Documents/Arduino/homie_heatPump/sming_heatpump/app/application.cpp:165
0x4010183a: malloc at ??:?
0x4024a578: std::_Function_base::_Base_manager<void (*)(RbootHttpUpdater&, bool)>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) at /opt/esp-open-sdk/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.5/functional:1934
0x4024a560: std::_Function_handler<void (RbootHttpUpdater&, bool), void (*)(RbootHttpUpdater&, bool)>::_M_invoke(std::_Any_data const&, RbootHttpUpdater&, bool) at /opt/esp-open-sdk/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.5/functional:2069
0x4023bc19: String::copy(char const*, unsigned int) at /opt/Sming/Sming/Wiring/WString.cpp:823 (discriminator 3)
0x4023be94: String::operator=(String const&) at /opt/Sming/Sming/Wiring/WString.cpp:823 (discriminator 3)
0x4023b9e6: String::invalidate() at /opt/Sming/Sming/Wiring/WString.cpp:823 (discriminator 3)
0x40234c40: onMessageReceived(String, String) at /opt/Sming/Sming/Wiring/WString.h:200
 (inlined by) onMessageReceived(String, String) at /Users/kevinpeck/Documents/Arduino/homie_heatPump/sming_heatpump/app/application.cpp:420
f7a4  
3ffffcf0:  3ffef6bc 3ffffd4c 40234ac8 3ffef7a4  
3ffffd00:  3ffef6bc 3ffffd4c 40234ac8 40233712  
3ffffd10:  3fff25e8 0000004a 0000004a 3fff2488  
3ffffd20:  0000001b 0000001b 402336f0 40233618  
3ffffd30:  3ffef6bc 3ffef5d4 402336f0 402336af  
3ffffd40:  00000000 00000000 00000000 00000000  
3ffffd50:  00000000 00000000 00000000 00000000  
3ffffd60:  00000000 00000000 00000000 00000000  
3ffffd70:  3fff2520 0000004a 0000004a 3fff2458  
3ffffd80:  0000001b 0000001b 3ffee910 00000030  
3ffffd90:  40205dcd 3ffef798 3ffef5d4 4024a542  
3ffffda0:  3ffef6bc 3ffef798 3ffef5d4 40238cac  
3ffffdb0:  4022f900 3fff23b8 00000000 401009cd  
3ffffdc0:  3ffef7e8 3ffef798 00000069 3ffec1de  
3ffffdd0:  00000069 3ffef798 3ffef7e8 40243357  
3ffffde0:  0000004a 3ffee910 0000001a 3fff2690  
3ffffdf0:  00000005 00000000 00000020 3ffef638  
3ffffe00:  3fff23a0 3fff23a0 3ffef5d4 4023810b  
3ffffe10:  40105973 3ffed9e0 3ffe9b20 0000001a  
3ffffe20:  fffffff4 03bcb69c 3ffee128 40100x40234ac8: onMessageReceived(String, String) at /Users/kevinpeck/Documents/Arduino/homie_heatPump/sming_heatpump/app/application.cpp:389
0x40234ac8: onMessageReceived(String, String) at /Users/kevinpeck/Documents/Arduino/homie_heatPump/sming_heatpump/app/application.cpp:389
0x40233712: std::_Function_handler<void (String, String), void (*)(String, String)>::_M_invoke(std::_Any_data const&, String, String) at /Users/kevinpeck/Documents/Arduino/homie_heatPump/sming_heatpump/app/application.cpp:165
 (inlined by) std::_Function_handler<void (String, String), void (*)(String, String)>::_M_invoke(std::_Any_data const&, String, String) at /opt/esp-open-sdk/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.5/functional:2071
0x402336f0: std::_Function_handler<void (String, String), void (*)(String, String)>::_M_invoke(std::_Any_data const&, String, String) at /Users/kevinpeck/Documents/Arduino/homie_heatPump/sming_heatpump/app/application.cpp:165
0x40233618: String::String(String&&) at /Users/kevinpeck/Documents/Arduino/homie_heatPump/sming_heatpump/app/application.cpp:165
0x402336f0: std::_Function_handler<void (String, String), void (*)(String, String)>::_M_invoke(std::_Any_data const&, String, String) at /Users/kevinpeck/Documents/Arduino/homie_heatPump/sming_heatpump/app/application.cpp:165
0x402336af: MqttClient::onPublish(MqttClient&, mqtt_message_u*) at /Users/kevinpeck/Documents/Arduino/homie_heatPump/sming_heatpump/app/application.cpp:165
 (inlined by) std::function<void (String, String)>::operator()(String, String) const at /opt/esp-open-sdk/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.5/functional:2471
 (inlined by) MqttClient::onPublish(MqttClient&, mqtt_message_u*) at /opt/Sming/Sming/Core/Network/MqttClient.h:278
0x40205dcd: ieee80211_parse_beacon at ??:?
0x4024a542: std::_Function_handler<int (MqttClient&, mqtt_message_u*), int (*)(MqttClient&, mqtt_message_u*)>::_M_invoke(std::_Any_data const&, MqttClient&, mqtt_message_u*) at /opt/esp-open-sdk/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.5/functional:2058
0x40238cac: std::function<int (MqttClient&, mqtt_message_u*)>::operator()(MqttClient&, mqtt_message_u*) const at /opt/Sming/Sming/Wiring/Countable.h:23
 (inlined by) MqttClient::staticOnMessageEnd(void*, mqtt_message_u*) at /opt/Sming/Sming/Core/Network/MqttClient.cpp:182
0x4022f900: strrchr at ??:?
0x401009cd: std::function<int (MqttPayloadParserState&, mqtt_message_u*, char const*, int)>::operator()(MqttPayloadParserState&, mqtt_message_u*, char const*, int) const at /opt/Sming/Sming/Wiring/Countable.h:23
0x40243357: mqtt_parser_process at /opt/Sming/Sming/Components/mqtt-codec/src/parser.c:565
 (inlined by) mqtt_parser_execute at /opt/Sming/Sming/Components/mqtt-codec/src/parser.c:593
0x4023810b: MqttClient::onTcpReceive(TcpClient&, char*, int) at /opt/Sming/Sming/Wiring/Countable.h:23
0x40105973: wDev_IndicateFrame at /home/xcg/workspace/debug/esp8266_nonos_sdk_core_20180510/app/pp/wdev.c:324
5b4c  
3ffffe30:  3ffec1de 00000069 00000000 3ffee128  
3ffffe40:  fffffff4 3fff23a0 3ffef5d4 4024a9df  
3ffffe50:  3ffea850 00000000 7fffffff 402392ea  
3ffffe60:  00000001 00004288 4000050c 3ffef564  
3ffffe70:  00000000 3fff23a0 3ffef5d4 40239cd1  
3ffffe80:  00000000 2c9f0300 4000050c 00000000  
3ffffe90:  3fffc278 40105d28 3fffc200 00000022  
3ffffea0:  4000006e 129d9d1f 4020a9da 3fff1488  
3ffffeb0:  3fff0ba8 3fff0bb0 00000006 3ffef564  
3ffffec0:  3fff22e0 3fff22e0 3fff23a0 40239d58  
3ffffed0:  3fff22e0 3ffef56c 3ffef568 4021fc6c  
3ffffee0:  6501a8c0 00000018 6801a8c0 00000018  
3ffffef0:  00000000 3fff2390 00000184 4021a4f9  
3fffff00:  3ffe0000 0000009f 00000024 3fff0bac  
3fffff10:  3ffec1b6 3fff0bb0 3fff23a0 4021d3bd  
3fffff20:  00754288 3fff1c20 3fff1c20 3ffec18c  
3fffff30:  00000000 3fff23a0 0000001c 3ffec1a8  
3fffff40:  3fffdc80 3fff23a0 3fff1c20 4021dd51  
3fffff50:  000000c7 3ffee910 00000000 00000019  
3fffff60:  0000001a 3fff2078 00000002 40220x40105b4c: wDev_ProcessRxSucData at /home/xcg/workspace/debug/esp8266_nonos_sdk_core_20180510/app/pp/wdev.c:603
0x4024a9df: std::_Function_handler<bool (TcpClient&, char*, int), Delegate<bool (TcpClient&, char*, int)>::Delegate<MqttClient>(bool (MqttClient::*)(TcpClient&, char*, int), MqttClient*)::{lambda(TcpClient&, char*, int)#1}>::_M_invoke(std::_Any_data const&, TcpClient&, char*, int) at /opt/esp-open-sdk/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.5/functional:2058
0x402392ea: std::function<bool (TcpClient&, char*, int)>::operator()(TcpClient&, char*, int) const at /opt/Sming/Sming/Wiring/Stream.h:32
 (inlined by) TcpClient::onReceive(pbuf*) at /opt/Sming/Sming/Core/Network/TcpClient.cpp:110
0x4000050c: ?? ??:0
0x40239cd1: TcpConnection::internalOnReceive(pbuf*, signed char) at /opt/Sming/Sming/Core/Network/TcpConnection.cpp:464
0x4000050c: ?? ??:0
0x40105d28: wDev_ProcessFiq at /home/xcg/workspace/debug/esp8266_nonos_sdk_core_20180510/app/pp/wdev.c:1072
0x4000006e: ?? ??:0
0x4020a9da: sta_input at ??:?
0x40239d58: TcpConnection::initialize(tcp_pcb*)::{lambda(void*, tcp_pcb*, pbuf*, signed char)#2}::_FUN(void*, tcp_pcb*, pbuf*, signed char) at /opt/Sming/Sming/Core/Network/TcpConnection.cpp:316
 (inlined by) _FUN at /opt/Sming/Sming/Core/Network/TcpConnection.cpp:318
0x4021fc6c: tcp_input at /opt/Sming/Sming/Arch/Esp8266/Components/esp-open-lwip/esp-open-lwip/lwip/core/tcp_in.c:394 (discriminator 1)
0x4021a4f9: pbuf_alloc at /opt/Sming/Sming/Arch/Esp8266/Components/esp-open-lwip/esp-open-lwip/lwip/core/pbuf.c:909 (discriminator 3)
0x4021d3bd: ip_input at /opt/Sming/Sming/Arch/Esp8266/Components/esp-open-lwip/esp-open-lwip/lwip/core/ipv4/ip.c:559
0x4021dd51: ethernet_input at /opt/Sming/Sming/Arch/Esp8266/Components/esp-open-lwip/esp-open-lwip/lwip/netif/etharp.c:1379
c1bf  
3fffff70:  3ffed9e0 3ffec180 3fffdcc0 3ffea0c8  
3fffff80:  4022c132 3ffed9e0 00000000 3fff1ca0  
3fffff90:  3fffdc80 00000000 3fff23a0 4021848b  
3fffffa0:  40000f49 3fffdab0 01000081 40000f49  
0x4022c1bf: ppRxPkt at /home/xcg/workspace/debug/esp8266_nonos_sdk_core_20180510/app/pp/pp.c:1086
0x4022c132: ppRxPkt at /home/xcg/workspace/debug/esp8266_nonos_sdk_core_20180510/app/pp/pp.c:1086
0x4021848b: ets_snprintf at ??:?
0x40000f49: ?? ??:0
0x40000f49: ?? ??:0
^CTraceback (most recent call last):
  File "/opt/Sming/Sming/Arch/Esp8266/Tools/decode-stacktrace.py", line 40, in <module>
    data = sys.stdin.readline()
@kpishere
Copy link
Author

kpishere commented Aug 26, 2020

Added the following upon receipt of OTA request spiffs_unmount(); and now it does not crash. However, it does not make this second download request as expected.

Also, the callback never happens so it appears to never switch roms.

@kpishere
Copy link
Author

Here is some serial output. First, from flash via UART :

SDK: v3.0.3(8427744)
Free Heap: 45024
CPU Frequency: 80 MHz
System Chip ID: 103728
SPI Flash ID: 164020
112287 Count: 2
112372 ROM 0: 2000
113421 ROM 1: 82000
115242 ROM 2: 0
116721 GPIO ROM: 0
118457 current ROM: 0
120535 fs.start: size:256 Kb, offset:0x100000

130333 mount res: 0
load fileOpen("control.config") = 1
Loaded: {IsOn:0 , Instr:1 , Mode:0 , FanSpeed:0 , IsSleepOn:0 , SetTemp:22 }

Sending message : 0xa1 20 5 0 3 e8 5e df fa ff fc 17 
3137394 Station configuration is: 21BirchleaAve
mode : sta(bc:dd:c2:10:37:28) + softAP(be:dd:c2:10:37:28)
add if0
add if1
dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1)
bcn 100
3228317 mode: 0 -> 3

scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 5
cnt 

connected with 21BirchleaAve, channel 1
dhcp client start...
3307332 connect to ssid 21BirchleaAve, channel 1

ip:192.168.1.101,mask:255.255.255.0,gw:192.168.1.1
7266171 ip:192.168.1.101,mask:255.255.255.0,gw:192.168.1.1

Connecting to mqtt://192.168.1.104:1883/
Connected to 192.168.1.104
Sending message : 0xa2 8 ff ff ff 75 5d f7 0 0 0 8a 
Memory free=40056
Sending message : 0xa2 8 ff ff ff 75 5d f7 0 0 0 8a 
Sending message : 0xa2 8 ff ff ff 75 5d f7 0 0 0 8a 
Memory free=40088
Sending message : 0xa2 1 ff ff ff 7c 5d fe 0 0 0 83 
Sending message : 0xa2 1 ff ff ff 7c 5d fe 0 0 0 83 
Memory free=40088
Sending message : 0xa2 1 ff ff ff 7c 5d fe 0 0 0 83 
Memory free=40088
hvac/heatpump/ota/rom_spiff: http://192.168.1.104:8000/rom0.bin http://192.168.1.104:8000/spiff_rom.bin
Updating...
MQTT Broker Unreachable.

... some minutes ...

Connecting to mqtt://192.168.1.104:1883/
Connected to 192.168.1.104
Sending message : 0xa2 8 ff ff ff 75 5d f7 0 0 0 8a 
Sending message : 0xa2 8 ff ff ff 75 5d f7 0 0 0 8a 
Memory free=38248
Sending message : 0xa2 8 ff ff ff 75 5d f7 0 0 0 8a 
Sending message : 0xa2 1 ff ff ff 7c 5d fe 0 0 0 83 
Memory free=38248
Sending message : 0xa2 1 ff ff ff 7c 5d fe 0 0 0 83 
Sending message : 0xa2 1 ff ff ff 7c 5d fe 0 0 0 83 
Memory free=38248

@kpishere
Copy link
Author

kpishere commented Sep 2, 2020

Turned on debugging and in going through output I see the pertinant parts :

Mqtt receives the message, it unsubscribes, and closes TCP, then flash upgrade starts ...

hvac/heatpump/ota/rom_spiff: http://192.168.1.104:8000/rom0.bin http://192.168.1.104:8000/spiff_rom.bin
38993125 unsubscribing from 'hvac/heatpump/control'
38995453 unsubscribing from 'hvac/heatpump/ota/rom_spiff'
MQTT Broker Disconnected.
39002831 TCP 3ffef69c connection closing
39006451 KMQTT closed previous connection
Updating...slot current 0...slot new 1...loaded http://192.168.1.104:8000/rom0.bin...loaded http://192.168.1.104:8000/spiff_rom.bin...
39021956 Download file:
    (0) http://192.168.1.104:8000/rom0.bin -> 82000
39029421 Creating new HttpClientConnection
39032793 HttpClientConnection::connect: TCP state: -1, isStarted: 0, isActive: 0
39039577 HttpClientConnection::connecting ...
39043761 TCP 3fff2c40 +connection
39046691 TCP 3fff2c40 connect to "192.168.1.104"
39052117 TCP connect result: 0
39053859 Download file:
    (0) http://192.168.1.104:8000/spiff_rom.bin -> 300000
39061694 HttpClientConnection::connect: TCP state: 2, isStarted: 1, isActive: 1

but then MQTT restarts ... this is problem

39068270 TCP 3ffef69c received: 105 bytes
39072666 -TCP connection
Connecting to mqtt://192.168.1.104:1883/
39077868 MQTT closed previous connection
39081378 MQTT start connection
39084320 TCP 3ffef69c +connection
39087194 TCP 3ffef69c connect to "192.168.1.104"
39092069 TCP connect result: 0
39094360 subscription 'hvac/heatpump/control' registered
39099468 subscription 'hvac/heatpump/ota/rom_spiff' registered
39122990 TCP 3fff2c40 connected: useSSL: 0, Error: 0
39123258 TCP 3fff2c40 connected
39123397 HttpClientConnection::onReadyToSendData: waitingQueue.count: 2
39126337 MemoryDataStream::realloc 0 -> 24
39129811 Storing 24 bytes in stream

@kpishere
Copy link
Author

kpishere commented Sep 3, 2020

Hmm... ok, removed this problem by having MQTT safe the info to SPIFFS and cause software reboot. On boot, before MqttClient is instanciated, check for OTA param file, then rBoot ... there is no MqttClient in this boot sequence now. The result is the below ... something is still wrong here, it does not switch roms.

'''
SDK: v3.0.3(8427744)
Free Heap: 45520
CPU Frequency: 80 MHz
System Chip ID: 103728
SPI Flash ID: 164020
112615 Count: 2
112700 ROM 0: 2000
113744 ROM 1: 82000
115567 ROM 2: 0
117042 GPIO ROM: 0
118777 current ROM: 0
120862 fs.start: size:256 Kb, offset:0x100000

130648 mount res: 0
load fileOpen("control.config") = 1
Loaded: {IsOn:0 , Instr:1 , Mode:0 , FanSpeed:0 , IsSleepOn:0 , SetTemp:22 }

Sending message : 0xa1 20 5 0 0 eb 5e df fa ff ff 14
3137671 Station configuration is: 21BirchleaAve
mode : sta(bc:dd:c2:10:37:28) + softAP(be:dd:c2:10:37:28)
add if0
add if1
dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1)
bcn 100
3243513 mode: 0 -> 3

scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 5
cnt

connected with 21BirchleaAve, channel 1
dhcp client start...
3307241 connect to ssid 21BirchleaAve, channel 1

ip:192.168.1.101,mask:255.255.255.0,gw:192.168.1.1
7291462 ip:192.168.1.101,mask:255.255.255.0,gw:192.168.1.1

load fileOpen("ota.txt") = 2
Loaded: http://192.168.1.104:8000/rom0.bin http://192.168.1.104:8000/spiff_rom.bin
Updating...slot current 0...slot new 1...loaded http://192.168.1.104:8000/rom0.bin...loaded http://192.168.1.104:8000/spiff_rom.bin...
7311240 Download file:
(0) http://192.168.1.104:8000/rom0.bin -> 82000
7318598 Creating new HttpClientConnection
7321889 HttpClientConnection::connect: TCP state: -1, isStarted: 0, isActive: 0
7328598 HttpClientConnection::connecting ...
7332721 TCP 3fff2458 +connection
7335538 TCP 3fff2458 connect to "192.168.1.104"
7340937 TCP connect result: 0
7342502 Download file:
(0) http://192.168.1.104:8000/spiff_rom.bin -> 300000
7350185 HttpClientConnection::connect: TCP state: 2, isStarted: 1, isActive: 1
7369473 TCP 3fff2458 connected: useSSL: 0, Error: 0
7369700 TCP 3fff2458 connected
7369829 HttpClientConnection::onReadyToSendData: waitingQueue.count: 2
7372562 MemoryDataStream::realloc 0 -> 24
7375905 Storing 24 bytes in stream
7379441 MemoryDataStream::realloc 24 -> 178
7382920 Storing 26 bytes in stream
7386081 Storing 19 bytes in stream
7389158 Storing 2 bytes in stream
7392223 TCP 3fff2458 onReadyToSendData: 0
7396140 TCP 3fff2458 Written: 71, Available: 2780, isFinished: 0, PushCount: 1
7402890 TcpClient stream finished
7405930 HttpClientConnection::onReadyToSendData: waitingQueue.count: 1
7412293 MemoryDataStream::realloc 0 -> 29
7415876 Storing 29 bytes in stream
7419233 MemoryDataStream::realloc 29 -> 183
7422916 Storing 26 bytes in stream
7426076 Storing 19 bytes in stream
7429152 Storing 2 bytes in stream

...

17241447 Nothing in the waiting queue
17244847 TCP 3fff2458 onReadyToSendData: 1
17278235 rboot_write_flash: item.size: 344533
17278653 TCP 3fff2458 received: 1390 bytes
17278810 HttpClientConnection::onReadyToSendData: waitingQueue.count: 0
17281642 Nothing in the waiting queue
17285042 TCP 3fff2458 onReadyToSendData: 1
17292649 rboot_write_flash: item.size: 344704
17293071 staticOnMessageComplete: Execution queue: 1, http://192.168.1.104:8000/rom0.bin
17300770 Finished: URL: http://192.168.1.104:8000/rom0.bin, Offset: 532480, Length: 344704
17309380 TCP 3fff2458 received: 171 bytes
17312459 HttpClientConnection::onReadyToSendData: waitingQueue.count: 0
17318771 Nothing in the waiting queue
17322170 TCP 3fff2458 onReadyToSendData: 1
17326161 TCP 3fff2458 receive: pbuf is NULL
17329875 TCP 3fff2458 received: (null)
17333389 TCP 3fff2458 connection closing
17465647 -TCP connection
'''

@kpishere
Copy link
Author

kpishere commented Sep 3, 2020

Noticed the rom addresses aren't what is specified in the component.mk file.

that was fixed with make flashconfig. Now it shows

SDK: v3.0.3(8427744)
Free Heap: 45520
CPU Frequency: 80 MHz
System Chip ID: 103728
SPI Flash ID: 164020
113671 Count: 2
113756 ROM 0: 2000
114800 ROM 1: 202000
116709 ROM 2: 0
118184 GPIO ROM: 0
119919 current ROM: 0
122004 fs.start: size:256 Kb, offset:0x100000

But still, at the end of loading the file, the callback does not happen. ...

17833499 Nothing in the waiting queue
17836898 TCP 3fff2468 onReadyToSendData: 1
17843700 rboot_write_flash: item.size: 344704
17844869 staticOnMessageComplete: Execution queue: 1, http://192.168.1.104:8000/rom0.bin
17852630 Finished: URL: http://192.168.1.104:8000/rom0.bin, Offset: 2105344, Length: 344704
17861312 TCP 3fff2468 received: 171 bytes
17864403 HttpClientConnection::onReadyToSendData: waitingQueue.count: 0
17870713 Nothing in the waiting queue
17874114 TCP 3fff2468 onReadyToSendData: 1
17878104 TCP 3fff2468 receive: pbuf is NULL
17881818 TCP 3fff2468 received: (null)
17885332 TCP 3fff2468 connection closing
18016779 -TCP connection

@kpishere
Copy link
Author

kpishere commented Sep 4, 2020

Ah! Ok, although the example shows loading a rom and then spiff section ... the rBoot only works with loading ONE file and then rebooting. So, for my case above, I was attempthig to load both roms. If I load just one, it works fine. I suspect the isue may be here ...

by using the delegate request->onRequestComplete(RequestCompletedDelegate(&RbootHttpUpdater::itemComplete, this)); there is never a return to the for loop.

So, I don't have a fix but call out the issue.

void RbootHttpUpdater::start()
{
	for(unsigned i = 0; i < items.count(); i++) {
		RbootHttpUpdaterItem& it = items[i];
		debug_d("Download file:\r\n    (%d) %s -> %X", currentItem, it.url.c_str(), it.targetOffset);

		HttpRequest* request;
		if(baseRequest != nullptr) {
			request = baseRequest->clone();
			request->setURL(it.url);
		} else {
			request = new HttpRequest(it.url);
		}

		request->setMethod(HTTP_GET);

		if(it.stream == nullptr) {
			it.stream = new RbootOutputStream(it.targetOffset, it.size);
		}

		request->setResponseStream(it.stream);

		if(i == items.count() - 1) {
			request->onRequestComplete(RequestCompletedDelegate(&RbootHttpUpdater::updateComplete, this));
		} else {
			request->onRequestComplete(RequestCompletedDelegate(&RbootHttpUpdater::itemComplete, this));
		}

		if(!send(request)) {
			debug_e("ERROR: Rejected sending new request.");
			break;
		}
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant