homie-esp8266 icon indicating copy to clipboard operation
homie-esp8266 copied to clipboard

Cannot change config by publishing to $implementation/config/set on ESP-01

Open jmozmoz opened this issue 6 years ago • 11 comments

Using the bare minimum example, I am trying to update the settings using the way described at https://marvinroger.github.io/homie-esp8266/docs/develop/others/ota-configuration-updates/

This is the command to publish the new config and the json file: mosquitto_pub -h alpha -p 1883 -u xxx -P 'yyy' -t 'homie/bare/$implementation/config/set' -f test.json

{
        "name": "bare_up"
}

This is the output on the serial console:

✔ Configuration updated
Flagged for reboot
Device is idle
↻ Rebooting...

 ets Jan  8 2013,rst cause:2, boot mode:(1,6)


 ets Jan  8 2013,rst cause:4, boot mode:(1,6)

wdt reset

The output from the broker during the update process:

homie/bare/$implementation/version 2.0.0
homie/bare/$implementation/ota/enabled true
homie/bare/$online true
homie/bare/$implementation/config/set {
        "name": "bare_up"
}

homie/bare/$implementation/config/set (null)
homie/bare/$online false

Then the ESP-01 stops.

If I reset it manually, the output on the serial device is:

Configuration invalid. Using CONFIG MODE
💡 Firmware bare-minimum (1.0.0)
🔌 Booting into config mode 🔌
Device ID is xxxxxxxxx
AP started as Homie-xxxxxxxxxx with IP 192.168.123.1
Triggering Wi-Fi scan...
✔ Wi-Fi scan completed

Here is main.cpp and platformio.ini:

#include <Homie.h>

void setup() {
  Serial.begin(115200);
  Serial << endl << endl;
  Homie.disableLedFeedback();

  Homie_setFirmware("bare-minimum", "1.0.0"); // The underscore is not a typo! See Magic bytes
  Homie.setup();
}

void loop() {
  Homie.loop();
}
; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html

[env:esp01_1m]
platform = espressif8266
board = esp01_1m
framework = arduino
lib_deps = https://github.com/marvinroger/homie-esp8266.git

; Serial Monitor options
monitor_speed = 115200

jmozmoz avatar May 19 '18 21:05 jmozmoz

Think this was a bug, but has been fixed in my fork V2.1, if you have a sec, could you test on my v2.1 ?

https://github.com/timpur/homie-esp8266/tree/v2.1

Just point your lib_dep to https://github.com/timpur/homie-esp8266#v2.1, I think

timpur avatar May 19 '18 22:05 timpur

Unfortunately, this does not solve the problem:

💾 Saved config file.
✔ Configuration updated
Flagged for reboot
Device is idle
Triggering ABOUT_TO_RESTART event...
↻ Rebooting...
✖ MQTT disconnected
Triggering MQTT_DISCONNECTED event...
✖ Wi-Fi disconnected
Triggering WIFI_DISCONNECTED event...

 ets Jan  8 2013,rst cause:2, boot mode:(1,6)


 ets Jan  8 2013,rst cause:4, boot mode:(1,6)

wdt reset

↻ Config file loading
✖ Config file faild to load
✖ /homie/config.json doesn't exist
Configuration invalid. Using CONFIG MODE
💡 Firmware bare-minimum (1.0.0)
🔌 Booting into config mode 🔌
Device ID is xxxxx
AP started as Homie-xxxxx with IP 192.168.123.1

jmozmoz avatar May 19 '18 22:05 jmozmoz

Odd, I'll have a look into later today

timpur avatar May 19 '18 23:05 timpur

Did you find any reason for this effect/bug? Can I help debugging?

jmozmoz avatar May 27 '18 21:05 jmozmoz

Sorry, lacking for time... Will try got to this asap.

Can you tell me what module you use and how much flash and what spifs size ?

timpur avatar May 27 '18 22:05 timpur

Are you using an ESP-01 with a PUYA flash on it?? I ran into exactly the same issue with a new set of ESP-01's I was sent from Ali. It seems the new puya flash has some issues. I had to apply the same patch to esp.cpp to get the SPIFFS working. https://github.com/esp8266/Arduino/issues/4061

plambrechtsen avatar Jun 04 '18 07:06 plambrechtsen

@plambrechtsen you are right. Applying the patch https://github.com/esp8266/Arduino/issues/4061#issuecomment-368273656 solves the problem.

jmozmoz avatar Jun 04 '18 23:06 jmozmoz

Awesome, glad to hear it helped. It had me stumped for quite some time wondering why SPIFFS wasn't working as I couldn't set the initial config or the upload of the ui_bundle.gz wasn't working either.

plambrechtsen avatar Jun 05 '18 03:06 plambrechtsen

This is interesting to know, sorry I haven't found time to look into this deaply, but when I do, good to know this ... Not sure how to fix this, might be something to add to docks ...

timpur avatar Jun 05 '18 04:06 timpur

I don't think this is something that could easily be fixed in homie as it's an underlying issue with the esp8266 SPIFFS writing function. Unless you wanted to lift and shift all of that into Homie which I certainly wouldn't recommend. Otherwise you could add logic into the Web UI and serial console that reads back the config.json file after writing it. If it isn't able to read the config back then you know you have the issue with SPIFFS not working. Another thought about how this could be worked around is to have an option to write the config into offsets in the EEPROM but that would require agreeing particular offsets for where particular configuration items would sit rather than having a free text json file and being limited to 512/1024 bytes. Which would completely change how config is currently managed today.

plambrechtsen avatar Jun 05 '18 04:06 plambrechtsen

Is it possible to monkey patch that routine (EspClass::flashWrite)?

Otherwise, it would be helpful if it is documented: ESP-01 + PUYA flash => patch your framework.

jmozmoz avatar Jun 06 '18 00:06 jmozmoz