Open kpishere opened 3 years ago
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.
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
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
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 '''
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
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;
}
}
}
I have a project with MQTT client and am attempting to use rBoot also. Config file is thus :
Upon publishing URL to a topic, the MQTT calls :
The ota functions are lifted from the basic sample :
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 :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?