Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

AWS Shadow update not called when using ota-aws-shadow

Hi,
I'm working around an IoT prototype using Mongoose OS and AWS IoT on an ESP8266 dev-board. Everything seems ok until I mix these 2 function: custom AWS shadow update and ota-aws-shadow library.
My firmware is based on the js-demo-bundle, the only lib in mos.yml is:

libs:
  - origin: https://github.com/mongoose-os-libs/js-demo-bundle

the main.c file is the default one and the index.js relevant part is this, based on the api_aws.js example:
AWS.Shadow.setStateHandler(function(data, event, reported, desired) {
  if (event === AWS.Shadow.CONNECTED) {
    print("AWS.Shadow.CONNECTED: ", JSON.stringify(reported), JSON.stringify(desired));
    AWS.Shadow.update(0, {reported: state});  // Report device state on connection
  } else if (event === AWS.Shadow.UPDATE_DELTA) {
    ...
  }
}, null);

Console output after rebooting is this:

[Dec  1 14:59:19.381] mgos_net_on_change_c WiFi STA: connected
[Dec  1 14:59:22.033] ip:172.20.10.2,mask:255.255.255.240,gw:172.20.10.1
[Dec  1 14:59:22.035] mgos_net_on_change_c WiFi STA: ready, IP 172.20.10.2, GW 172.20.10.1, DNS 172.20.10.1
[Dec  1 14:59:22.045] mgos_mqtt_global_con MQTT connecting to axxxxxxawtdddf.iot.eu-central-1.amazonaws.com:8883
[Dec  1 14:59:22.083] mongoose_poll        New heap free LWM: 27576
[Dec  1 14:59:22.209] mongoose_poll        New heap free LWM: 27144
[Dec  1 14:59:22.467] SW ECDSA verify curve 3 hash_len 32 sig_len 71
[Dec  1 14:59:27.490] SW ECDSA verify curve 3 hash_len 64 sig_len 71
[Dec  1 14:59:32.366] SW ECDH curve 3
[Dec  1 14:59:39.754] mongoose_poll        New heap free LWM: 13744
[Dec  1 14:59:39.854] pm open,type:2 0
[Dec  1 14:59:39.854] mgos_sntp_query      SNTP query to pool.ntp.org
[Dec  1 14:59:39.947] mgos_mqtt_ev         MQTT TCP connect ok (0)
[Dec  1 14:59:39.960] mgos_sntp_ev         SNTP reply from 193.234.225.237: time 1512136780.598900, local 24.674308, delta 1512136755.924592
[Dec  1 14:59:40.108] mgos_mqtt_ev         MQTT CONNACK 0
[Dec  1 14:59:40.117] do_subscribe         Subscribing to 'esp8266_04C085/rpc'
[Dec  1 14:59:40.121] do_subscribe         Subscribing to 'esp8266_04C085/rpc/#'
[Dec  1 14:59:40.275] mgos_aws_shadow_ev   Subscribed
[Dec  1 14:59:40.319] AWS.Shadow.CONNECTED:  {} {}
[Dec  1 14:59:40.322] mgos_upd_boot_get_st cur 0 prev 0 fwu 0
[Dec  1 14:59:40.327] mgos_aws_shadow_ev   Update: {"state": {"reported":{"ota_url": ""}}, "clientToken": "7337f8ed"}
[Dec  1 14:59:40.494] mgos_aws_shadow_ev   Version: 0 -> 799 (5)

As you can see, device correctly connects to wi-fi and AWS IoT broker. AWS.Shadow.CONNECTED event is fired, but the AWS.Shadow.update is called with a wrong state, only containing "ota_url" and not my custom state.
What I am missing?

Thank You.

Comments

  • Replacing mos.yml lib with the complete liste except ota-aws-shadow, the next run after flashing gives the expected output:

    [Dec  1 15:22:55.506] dhcp client start...
    [Dec  1 15:22:55.509] mgos_net_on_change_c WiFi STA: connected
    [Dec  1 15:22:56.540] ip:172.20.10.2,mask:255.255.255.240,gw:172.20.10.1
    [Dec  1 15:22:56.543] mgos_net_on_change_c WiFi STA: ready, IP 172.20.10.2, GW 172.20.10.1, DNS 172.20.10.1
    [Dec  1 15:22:56.552] mgos_mqtt_global_con MQTT connecting to axxxxxxawtdddf.iot.eu-central-1.amazonaws.com:8883
    [Dec  1 15:22:56.590] mongoose_poll        New heap free LWM: 27720
    [Dec  1 15:22:56.801] mongoose_poll        New heap free LWM: 27160
    [Dec  1 15:22:57.035] SW ECDSA verify curve 3 hash_len 32 sig_len 71
    [Dec  1 15:23:02.035] SW ECDSA verify curve 3 hash_len 64 sig_len 71
    [Dec  1 15:23:06.925] SW ECDH curve 3
    [Dec  1 15:23:14.264] mongoose_poll        New heap free LWM: 13640
    [Dec  1 15:23:14.376] pm open,type:2 0
    [Dec  1 15:23:14.376] mgos_mqtt_ev         MQTT TCP connect ok (0)
    [Dec  1 15:23:14.386] mgos_sntp_query      SNTP query to pool.ntp.org
    [Dec  1 15:23:14.532] mgos_mqtt_ev         MQTT CONNACK 0
    [Dec  1 15:23:14.540] do_subscribe         Subscribing to 'esp8266_04C085/rpc'
    [Dec  1 15:23:14.544] do_subscribe         Subscribing to 'esp8266_04C085/rpc/#'
    [Dec  1 15:23:14.559] mgos_sntp_ev         SNTP reply from 212.59.0.1: time 1512138194.771959, local 26.272568, delta 1512138168.499391
    [Dec  1 15:23:14.673] mgos_aws_shadow_ev   Subscribed
    [Dec  1 15:23:14.712] AWS.Shadow.CONNECTED:  {} {}
    [Dec  1 15:23:14.712] mgos_aws_shadow_ev   Update: {"state": {"reported":{"queue":[],"display":"Booting","monitor":0,"sensor":false,"roles":null,"resource":null}}, "clientToken": "7337f8ed"}
    [Dec  1 15:23:14.871] mgos_aws_shadow_ev   Version: 0 -> 801 (7)

    Maybe the problem is linked to the global state variable in mJS?

    Thank You.

  • I'll need to try to reproduce it myself, will let you know once done.

Sign In or Register to comment.