microsoft / azure-iot-developer-kit

A curated list of awesome Azure IoT Developer Kit projects and resources.
MIT License
94 stars 57 forks source link

DevKitSDK v1.6.1+ (state code = 400) #483

Closed manekinekko closed 4 years ago

manekinekko commented 5 years ago

Hi,

I'd like to report a weird behavior.

I was recently trying to upgrade our DevKitState workshop, and I stumbled upon an issue. After investigations, it turns out the DevKitSDK versions 1.6.1 and 1.6.2 are triggering the following issue, making the device unable to sync with the IoT Hub:

image

Switching back to v1.6.0 fixed those errors.

DevKitSDK version: 1.6.0
Mico version: 31620002.049
mbed-os version: 5.2.1
mbed TLS version: 2.4.2
WIFI version: wl0: Sep 10 2014 11:28:46 version 5.90.230.10

How to reproduce

  1. flash the MX chip with firmeware v1.6.2 (https://aka.ms/devkit/prod/firmware/latest)
  2. dl the MX chip package for Arduino v1.6.2
  3. compile and upload the DevKitState.ino file to the MX chip

Here is the current version log from the board

DevKitSDK version: 1.6.2
Mico version: 31620002.049
mbed-os version: 5.4.3
mbed TLS version: 2.15.0
WIFI version: wl0: Sep 10 2014 11:28:46 version 5.90.230.10

image

and the error message:

2019-06-25 14:47:42 INFO:  Iothub Version: 1.2.14

2019-06-25 14:47:45 INFO:  >>>Connection status: connected
2019-06-25 14:47:45 INFO:  >>>IoTHubClient_LL_SendReportedState accepted state for transmission to IoT Hub.
2019-06-25 14:47:45 INFO:  >>>Confirmation[0] received for state tracking id = 0 with state code = 400
2019-06-25 14:47:45 ERROR: DevKitMQTTClient.cpp (ln 337): Report confirmation failed with state code 400
2019-06-25 14:47:55 ERROR: DevKitMQTTClient.cpp (ln 409): Waiting for send confirmation, time is up 10044
2019-06-25 14:47:55 INFO:  >>>Re-connect.

Cheers.

guybartal commented 5 years ago

Try working outside of your office, mobile hot-spot for instance, might be firewall issue, happened to me...

danwale commented 5 years ago

Try working outside of your office, mobile hot-spot for instance, might be firewall issue, happened to me...

I'm having this exact same issue as well, I've tested on my mobile hot-spot and I've worked from home today to test on my home connection.

I haven't tested with an older version of the SDK to build an API but @manekinekko had and he confirmed that the problem appeared in v1.6.1 and v1.6.2 of the SDK which would tend to indicate it's not a network issue.

I've had other messages being sent to the Azure Hub (the get started project sends messages that I can monitor on the Hub) but what wasn't working was the Device Twin functionality with the temperatureAlert property, it seems like the report state to the Device Twin functionality in the SDK is failing.

aderici commented 4 years ago

Same here, not a network issue,

aderici commented 4 years ago

If anybody else comes across this issue, i tried looking at other files and use some newer methods, following seems to work and state updates are successfully sent. You need to edit DevKitState.ino file according to the following :

//  Old Code - Does not work

//  char state[500];
//  snprintf(state, 500, "{\"firmwareVersion\":\"%s\",\"wifiSSID\":\"%s\",\"wifiRSSI\":%d,\"wifiIP\":\"%s\",\"wifiMask\":\"%s\",\"macAddress\":\"%s\",\"sensorMotion\":%d,\"sensorPressure\":%d,\"sensorMagnetometer\":%d,\"sensorHumidityAndTemperature\":%d,\"sensorIrda\":%d}", firmwareVersion, wifiSSID, wifiRSSI, wifiIP, wifiMask, macAddress, sensorMotion, sensorPressure, sensorMagnetometer, sensorHumidityAndTemperature, sensorIrda);
//  DevKitMQTTClient_ReportState(state);
//  delay(600000);

// New Code, Does work

  char* state;

  JSON_Value* root_value = json_value_init_object();
  JSON_Object* root_object = json_value_get_object(root_value);

  // Only reported properties:

  (void)json_object_set_string(root_object, "firmwareVersion", firmwareVersion);
  (void)json_object_dotset_string(root_object, "wifi.wifiSSID", wifiSSID);
  (void)json_object_dotset_number(root_object, "wifi.wifiRSSI", wifiRSSI);
  (void)json_object_dotset_string(root_object, "wifi.wifiIP", WiFi.localIP().get_address());
  (void)json_object_dotset_string(root_object, "wifi.wifiMask", WiFi.subnetMask().get_address());
  (void)json_object_dotset_string(root_object, "wifi.macAddress", macAddress);

  (void)json_object_dotset_number(root_object, "sensor.sensorMotion", sensorMotion);
  (void)json_object_dotset_number(root_object, "sensor.sensorHumidityAndTemperature", sensorHumidityAndTemperature);
  (void)json_object_dotset_number(root_object, "sensor.sensorMagnetometer", sensorMagnetometer);
  (void)json_object_dotset_number(root_object, "sensor.sensorPressure", sensorPressure);
  (void)json_object_dotset_number(root_object, "sensor.sensorIrda", sensorIrda);

  state = json_serialize_to_string(root_value);

  json_value_free(root_value);

  DevKitMQTTClient_ReportState(state);
  delay(600000); //adjust according to your preferences.
JerryYangKai commented 4 years ago

Hi, we have released workbench 0.10.15 and fixed the bug. You can create a new sample project and check it.