Azure / azure-iot-arduino

Azure IoT library for the Arduino
Other
168 stars 95 forks source link

ESP8266 - Direct Methods #50

Closed Patrik-Berglund closed 7 years ago

Patrik-Berglund commented 7 years ago

Hi,

Tried out direct methods on a ESP8266 with Arduino, based on this example. https://github.com/Azure/azure-iot-sdk-c/tree/master/serializer/samples/devicemethod_simplesample

It crashes executing this method, METHODRETURN_HANDLE result = MethodReturn_Create(1, "{\"Message\":\"Turning fan on with Method\"}");

Setting the returned JSON payload to null makes it work, METHODRETURN_HANDLE result = MethodReturn_Create(1, NULL);

Exception from the ESP8266 serial debug, Result Call Back Called! Result is: IOTHUB_CLIENT_CONFIRMATION_OK <- PUBLISH | IS_DUP: false | RETAIN: 0 | QOS: DELIVER_AT_MOST_ONCE = 0x00 | TOPIC_NAME: $iothub/methods/POST/TurnFanOn_with_Method/?$rid=1 | PAYLOAD_LEN: 14 Turning fan on with Method. Fatal exception 28(LoadProhibitedCause): epc1=0x4020baa4, epc2=0x00000000, epc3=0x00000000, excvaddr=0x0000007c, depc=0x00000000

markrad commented 7 years ago

Hi @Patrik-Berglund,

Can you install the ESP Exception Decoder available here: https://github.com/me-no-dev/EspExceptionDecoder and then post the stack trace from that tool please?

Thank you.

Mark Radbourne MSFT

Patrik-Berglund commented 7 years ago

Hi @markrad

Here's the complete stack trace,

stack>>> 3fff3cc0: 40002514 3fffdd3c 3fff613c 3ffe96e0
3fff3cd0: 00000000 0000001c 00000008 00000000
3fff3ce0: 00000000 00000000 00000000 3ffe9330
3fff3cf0: 00000005 00000000 00000020 40101d02
3fff3d00: 3fff3d20 3fff3d20 00000004 00000000
3fff3d10: 00000001 3ffe9334 3fffa2bc 4020bf46
3fff3d20: 3ffe9334 3ffe9314 00000000 40201340
3fff3d30: 00ff0000 40404040 00000000 4020aa7d
3fff3d40: 3ffe96e0 3fff613c 3fffa2bc 4020132c
3fff3d50: 00000000 3fffa28c 3fff3dc0 40201367
3fff3d60: 3fffa2ac 3fff613c 3fffa2bc 40203e08
3fff3d70: 3fff3da0 00000000 00000000 4000050c
3fff3d80: 00000000 3fff3dc4 3fffa27d 3fff3df0
3fff3d90: 00000000 3ffea068 3ffe9640 40211c08
3fff3da0: 3fff8e6c 00000030 00000008 00000015
3fff3db0: 3fffa2ac 00000000 3fff619c 40205ce1
3fff3dc0: 3fff8e6c 3fff5a2c 3fffa2bc 40204f08
3fff3dd0: 00000000 00000000 40205ca4 3fffa26c
3fff3de0: 3fff5754 3fff61dc 3fff59d4 3fffa28c
3fff3df0: 00000000 00000000 00000000 00000000
3fff3e00: 00000000 3fff3ee0 3fff3ee0 3fffa24c
3fff3e10: 3fffa2bc 3fff61dc 00000000 40205511
3fff3e20: 3fffa28c 3fffa26c 00000004 4010068c
3fff3e30: 3fff317c 00000af1 00000af1 3fffa24c
3fff3e40: 0000001b 3fffa2bc 3fff6154 4020609c
3fff3e50: 0000001c 00005778 00000aef 40204ba9
3fff3e60: 3fffa24c 3fff3eb0 3fff3eb4 401004d8
3fff3e70: 0000001b 3fff3eb0 3fff3eb4 40201102
3fff3e80: 3fffa2bc 3fff6154 36363636 3fff8e4c
3fff3e90: 3fff317c 00000ae5 00000ae5 3fff5aac
3fff3ea0: 3fffa2fc 3fffa2e8 3fff5aac 4020680a
3fff3eb0: 00000000 00000000 3fff5cbc 40210f20
3fff3ec0: 00000000 3fffa2e8 3fffa2fc 4020870c
3fff3ed0: 3fff9014 3fffa2dc 3fffa304 3fff5bb4
3fff3ee0: 3fff317c 0000089e 0000089e 00000000
3fff3ef0: 3fffa2dc 3fff9014 3fff9014 4010068c
3fff3f00: 00000000 3fff9014 3fff5cbc 00000000
3fff3f10: 3fffa2dc 3fff9014 3fff5cbc 4021269c
3fff3f20: 901615d9 3fff30d0 3fff31d0 3fff30d0
3fff3f30: 3fff62e0 00080000 3fff31d0 3fff3098
3fff3f40: 3fff6304 00000000 0000001b 00000000
3fff3f50: 00000000 00000001 3fff62ae 00000000
3fff3f60: 00000000 0000004f 3fff8b0c 00000000
3fff3f70: 3fff5d2c 00000000 3fff5d2c 40213085
3fff3f80: 3fff5d2c 00000000 00000050 40213be4
3fff3f90: 3fff3fd0 00000051 0000007d 402164fd
3fff3fa0: ffffffe3 00000080 00000000 3fff5aac
3fff3fb0: 3fff5bb4 3fff5c24 3fff5cbc 4021202f
3fff3fc0: 00000000 1730538b 3fff6264 4020defc
3fff3fd0: 32004f30 746f6924 2f627568 6874656d
3fff3fe0: 2f73646f 54534f50 7275542f 6e61466e
3fff3ff0: 775f6e4f 5f687469 6874654d 3f2f646f
3fff4000: 64697224 227b313d 6874654d 6150646f
3fff4010: 616f6c79 223a2264 6c796150 2264616f
3fff4020: 40000f7d 00000030 00000011 ffffffff
3fff4030: 4010593a 00000023 fffed4bf 00000000
3fff4040: 00000007 00f9d000 00000000 402146a0
3fff4050: 00000000 3fff5d1c 3fff5cbc 40215380
3fff4060: 3fff5bb4 00f9d000 00000000 40212f9f
3fff4070: 00000000 3fff59c4 3fff4090 3fff6dc4
3fff4080: 3fff5bb4 3fff5c24 00000000 40209d64
3fff4090: 00058228 00000001 3fff61fc 00000000
3fff40a0: 3fff62b4 000000f0 00000001 00000000
3fff40b0: 000007d0 3fff4120 3fff4120 3ffeba46
3fff40c0: 3fff5c24 3fffdd3c 3fff5aac 3fff5aac
3fff40d0: 3fff6dc4 3fff643c 3fff59fc 00000000
3fff40e0: 00000000 00f9d000 00000000 3fff6dc4
3fff40f0: 3fff5ab4 00000000 3fff5aac 4020a1d8
3fff4100: 3fff5aac 00000000 3fff5aac 40206734
3fff4110: 00058228 3fff30d0 3fff31d0 3fff30d0
3fff4120: 3fff5ab4 3fff6dc4 40216ffc 3fff31d0
3fff4130: 40213d92 00000064 00000064 3fff6dc4
3fff4140: 3fff5aac 00000000 3fff6254 40201502
3fff4150: 3fff6164 3fff6168 3fff616c 3fff6170
3fff4160: 3fff6174 3fff6178 3fff617c 3fff6180
3fff4170: 3fff6184 3fff6188 3fff618c 3fff6190
3fff4180: 00000155 3fff6dc4 40216ffc 3fff31d0
3fff4190: 40213d92 00000064 00000064 3fff31c8
3fff41a0: 3fffdad0 3fff6154 3fff5aac 40201590
3fff41b0: 3fffda01 59042117 3fff319c 40216d5c
3fff41c0: 3fffdad0 00000000 3fff31c0 402154b4
3fff41d0: feefeffe feefeffe feefeffe 40217048
3fff41e0: feefeffe feefeffe 3fff31d0 40100718
<<<stack<<<

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

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

wdt reset

Decoded trace, Decoding 47 results 0x40101d02: pp_post at ?? line ? 0x4020bf46: json_parse_string at g:\Users\patri\Documents\Arduino\libraries\AzureIoTHub\src\sdk/parson.c line 1190 0x40201340: TurnFanOn_with_MethodWRAPPER at C:\Users\patri\AppData\Local\Temp\arduino_build_326528\sketch/iothub_client.c line 16 0x4020aa7d: MethodReturn_Create at g:\Users\patri\Documents\Arduino\libraries\AzureIoTHub\src\sdk/methodreturn.c line 27 (discriminator 1) 0x4020132c: TurnFanOn_with_Method at C:\Users\patri\AppData\Local\Temp\arduino_build_326528\sketch/iothub_client.c line 66 0x40201367: TurnFanOn_with_MethodWRAPPER at C:\Users\patri\AppData\Local\Temp\arduino_build_326528\sketch/iothub_client.c line 16 (discriminator 1) 0x40203e08: CodeFirst_InvokeMethod at g:\Users\patri\Documents\Arduino\libraries\AzureIoTHub\src\sdk/codefirst.c line 1524 0x40211c08: VECTOR_find_if at g:\Users\patri\Documents\Arduino\libraries\AzureIoTUtility\src\azure_c_shared_utility/vector.c line 300 0x40205ce1: DeviceInvokeMethod at g:\Users\patri\Documents\Arduino\libraries\AzureIoTHub\src\sdk/iotdevice.c line 31 0x40204f08: DecodeAndExecuteModelMethod at g:\Users\patri\Documents\Arduino\libraries\AzureIoTHub\src\sdk/commanddecoder.c line 18 : (inlined by) ScanMethodPathAndExecuteMethod at g:\Users\patri\Documents\Arduino\libraries\AzureIoTHub\src\sdk/commanddecoder.c line 526 : (inlined by) DecodeMethod at g:\Users\patri\Documents\Arduino\libraries\AzureIoTHub\src\sdk/commanddecoder.c line 626 0x40205ca4: DeviceInvokeMethod at g:\Users\patri\Documents\Arduino\libraries\AzureIoTHub\src\sdk/iotdevice.c line 31 0x40205511: CommandDecoder_ExecuteMethod at g:\Users\patri\Documents\Arduino\libraries\AzureIoTHub\src\sdk/commanddecoder.c line 739 0x4010068c: free at C:\Users\patri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266\umm_malloc/umm_malloc.c line 1733 0x4020609c: Device_ExecuteMethod at g:\Users\patri\Documents\Arduino\libraries\AzureIoTHub\src\sdk/iotdevice.c line 301 0x40204ba9: CodeFirst_ExecuteMethod at g:\Users\patri\Documents\Arduino\libraries\AzureIoTHub\src\sdk/codefirst.c line 1582 0x401004d8: malloc at C:\Users\patri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266\umm_malloc/umm_malloc.c line 1664 0x40201102: DeviceMethodCallback at C:\Users\patri\AppData\Local\Temp\arduino_build_326528\sketch/iothub_client.c line 16 0x4020680a: IoTHubClient_LL_DeviceMethodComplete at g:\Users\patri\Documents\Arduino\libraries\AzureIoTHub\src\sdk/iothub_client_ll.c line 1599 0x40210f20: STRING_TOKENIZER_destroy at g:\Users\patri\Documents\Arduino\libraries\AzureIoTUtility\src\azure_c_shared_utility/string_tokenizer.c line 201 0x4020870c: mqtt_notification_callback at g:\Users\patri\Documents\Arduino\libraries\AzureIoTHub\src\sdk/iothubtransport_mqtt_common.c line 82 0x4010068c: free at C:\Users\patri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266\umm_malloc/umm_malloc.c line 1733 0x4021269c: recvCompleteCallback at g:\Users\patri\Documents\Arduino\libraries\AzureIoTProtocol_MQTT\src\azure_umqtt_c/mqtt_client.c line 33 0x40213085: completePacketData at g:\Users\patri\Documents\Arduino\libraries\AzureIoTProtocol_MQTT\src\azure_umqtt_c/mqtt_codec.c line 589 0x40213be4: mqtt_codec_bytesReceived at g:\Users\patri\Documents\Arduino\libraries\AzureIoTProtocol_MQTT\src\azure_umqtt_c/mqtt_codec.c line 1104 0x402164fd: SSLContext::available() at C:\Users\patri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266WiFi\src/WiFiClientSecure.cpp line 517 0x4021202f: onBytesReceived at g:\Users\patri\Documents\Arduino\libraries\AzureIoTProtocol_MQTT\src\azure_umqtt_c/mqtt_client.c line 33 0x4020defc: tlsio_arduino_dowork at g:\Users\patri\Documents\Arduino\libraries\AzureIoTUtility\src\adapters/tlsio_arduino.c line 461 0x4010593a: ets_timer_arm_new at ?? line ? 0x402146a0: time at C:\Users\patri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/time.c line 105 0x40215380: xio_dowork at g:\Users\patri\Documents\Arduino\libraries\AzureIoTUtility\src\azure_c_shared_utility/xio.c line 166 0x40212f9f: mqtt_client_dowork at g:\Users\patri\Documents\Arduino\libraries\AzureIoTProtocol_MQTT\src\azure_umqtt_c/mqtt_client.c line 1124 0x40209d64: IoTHubTransport_MQTT_Common_DoWork at g:\Users\patri\Documents\Arduino\libraries\AzureIoTHub\src\sdk/iothubtransport_mqtt_common.c line 2535 0x4020a1d8: IoTHubTransportMqtt_DoWork at g:\Users\patri\Documents\Arduino\libraries\AzureIoTHub\src\sdk/iothubtransportmqtt.c line 115 0x40206734: IoTHubClient_LL_DoWork at g:\Users\patri\Documents\Arduino\libraries\AzureIoTHub\src\sdk/iothub_client_ll.c line 1599 0x40216ffc: esp_yield at C:\Users\patri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_main.cpp line 56 0x40213d92: delay at C:\Users\patri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_wiring.c line 53 0x40201502: MainLoop at C:\Users\patri\AppData\Local\Temp\arduino_build_326528\sketch/iothub_client.c line 264 (discriminator 1) 0x40216ffc: esp_yield at C:\Users\patri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_main.cpp line 56 0x40213d92: delay at C:\Users\patri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_wiring.c line 53 0x40201590: IoTHubEntry at ?? line ? 0x40216d5c: Print::println(char const*) at C:\Users\patri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/Print.cpp line 170 0x402154b4: loop at E:\Source\Repos\Coffee grinder\Arduino\CoffeeGrinder_V2/CoffeeGrinder_V2.ino line 29 0x40217048: loop_wrapper at C:\Users\patri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_main.cpp line 56 0x40100718: cont_norm at C:\Users\patri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/cont.S line 109

zzeekk commented 7 years ago

I struggled with the same exception some weeks ago, and found that it works if you modify the includes of parson.c as follows:

#include "parson.h"
#include "pgmspace.h"

#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <ctype.h>
#include <math.h>
#include <errno.h>

I dont understand the problem, but parson/json_string_parse works like that on esp8266. If anyone has an explanation for this and maybe a cleaner solution, that would be great...

Patrik-Berglund commented 7 years ago

@zzeekk Thank you :)

Got build errors with when I updated parscon.c with:

#include "parson.h"
#include "pgmspace.h"

#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <ctype.h>
#include <math.h>
#include <errno.h>

So I tested

#include "parson.h"
#include <Arduino.h>

// #include <stdio.h>
// #include <stdlib.h>
// #include <string.h>
// #include <ctype.h>
// #include <math.h>
#include <errno.h>

And now it works

markrad commented 7 years ago

I tested this with ArduinoJSON as an alternative to Parson and it appears to work without modification.

Mark Radbourne MSFT

zzeekk commented 7 years ago

Hello @markrad

Pleased to hear that it works with ArduinoJSON, but current azure-iot-arduino uses parson (https://github.com/Azure/azure-iot-arduino/blob/master/src/sdk/parson.c). This issue isn't solved in my opinion.

zetanet commented 7 years ago

Same issue here.. When i try to call Direct method via Device Explorer esp8266 crash with error..

Turning fan on with Method. Fatal exception 28(LoadProhibitedCause): epc1=0x4020b998, epc2=0x00000000, epc3=0x00000000, excvaddr=0x0000007c, depc=0x00000000

Exception (28): epc1=0x4020b998 epc2=0x00000000 epc3=0x00000000 excvaddr=0x0000007c depc=0x00000000

ctx: cont sp: 3fff3620 end: 3fff3cb0 offset: 01a0

stack>>> 3fff37c0: 40002514 3fffdd3c 3fff546c 3ffe97d4
3fff37d0: 00000000 0000001c 00000008 00000000
3fff37e0: 00000000 00000000 00000000 3ffe93a0
3fff37f0: 89cbfca3 53e30b3a 3d6a54dd 27415e1a
3fff3800: 3fff3820 3fff3820 00000004 00000000
3fff3810: 00000001 3ffe93a4 3fff7e54 4020bd9a
3fff3820: 3ffe93a4 3ffe9384 00000000 4020128c
3fff3830: 00ff0000 40404040 7bbbdd32 4020a8d1
3fff3840: 3ffe97d4 3fff546c 3fff7e54 40201278
3fff3850: 39197b34 f8cb00bb 88fae74b 402012b3
3fff3860: 3fff92f4 3fff546c 3fff7e54 40203d5c
3fff3870: 458e5b36 7f3068a9 ca758633 64f41e20
3fff3880: 00000000 3fff38b0 00000046 ffffff80
3fff3890: 00000000 3ffe9ae4 3ffe9734 40211a80
3fff38a0: 3fff5a4c 00000014 3fff3a10 00000015
3fff38b0: 3fff92f4 00000000 3fff5494 40205cb5
3fff38c0: 9b81b469 3fff4f34 3fff7e54 40204edc
3fff38d0: 00000000 00000000 40205c78 3fff92cc
3fff38e0: 3fff4fcc 3fff54d4 3fff4efc 3fff92d4
3fff38f0: 00000000 00000000 00000000 00000000
3fff3900: 00000000 00000000 00000000 3fff92ac
3fff3910: 3fff7e54 3fff54d4 00000000 402054e5
3fff3920: 3fff92d4 3fff92cc 5c5c5c5c 5c5c5c5c
3fff3930: 3fff2c30 000009a9 000009a9 3fff92ac
3fff3940: 00000002 3fff7e54 3fff5484 40206070
3fff3950: 0000001c 00004d38 000009a7 40204b7d
3fff3960: 3fff92ac 3fff39b0 3fff39b4 401004d8
3fff3970: 00000002 3fff39b0 3fff39b4 4020118e
3fff3980: 3fff7e54 3fff5484 36363636 3fff565c
3fff3990: 3fff2c30 0000099d 0000099d 3fff4fdc
3fff39a0: 3fff92b4 3fff5648 3fff4fdc 40206892
3fff39b0: 00000000 00000000 3fff523c 40210d98
3fff39c0: 00000000 3fff5648 3fff92b4 40208560
3fff39d0: 3fff8054 3fff563c 3fff92bc 3fff5104
3fff39e0: 00000000 00000002 3fff563c 00000000
3fff39f0: 3fff55f8 3fff5604 00000060 00000032
3fff3a00: 00000036 00000000 3fff523c 00000000
3fff3a10: 3fff563c 00000000 3fff523c 40212514
3fff3a20: 69b4819b 3ffedb94 3ffedb94 00000001
3fff3a30: 3fff55f8 00080000 3fff2c90 3fff2b4c
3fff3a40: 3fff5604 00000000 00000002 00000000
3fff3a50: 00000000 00000001 3fff55c6 00000000
3fff3a60: 00000000 00000036 3fff55b4 00000000
3fff3a70: 3fff52ac 00000000 3fff52ac 40212efd
3fff3a80: 3fff52ac 00000000 00000037 40213a5c
3fff3a90: 3fff3ad0 00000038 0000007d 402163cd
3fff3aa0: 00018000 00000080 00000000 3fff4fdc
3fff3ab0: 3fff5104 3fff5174 3fff523c 40211ea7
3fff3ac0: 40102a15 3fff0d08 3fff5564 4020dd74
3fff3ad0: 32003630 746f6924 2f627568 6874656d
3fff3ae0: 2f73646f 54534f50 7275542f 6e61466e
3fff3af0: 775f6e4f 5f687469 6874654d 3f2f646f
3fff3b00: 64697224 7d7b313d 3ffedb70 00000001
3fff3b10: 00000001 3fff523c 3fff523c 402151e1
3fff3b20: 3fff2c30 01454aec 00000000 4000050c
3fff3b30: 3fffc278 40102d7c 3fffc200 00000022
3fff3b40: 3ffedb94 00ccc000 00000000 40214518
3fff3b50: 00000000 3fff529c 3fff523c 402151f8
3fff3b60: 3fff5104 00ccc000 00000000 40212e17
3fff3b70: 00000000 3fff4ee4 3fff3b90 0000c4f5
3fff3b80: 3fff5104 3fff5174 00000000 40209bb8
3fff3b90: 00009858 00000000 00004f5d 00000030
3fff3ba0: 3fff55b4 000000f0 00000001 00000000
3fff3bb0: 3fff3bf0 3fff3bc0 00000004 402055ce
3fff3bc0: 3fff5174 3fff3c20 3fff3c30 3ffe95b6
3fff3bd0: 40107584 3fff5484 3fff4fdc 00000000
3fff3be0: 0000c4f5 00ccc000 00000000 0000c4f5
3fff3bf0: 3fff4fe4 3fff4fdc 3fff4fdc 4020a02c
3fff3c00: 00000000 3fff4fdc 3fff4fdc 402067bc
3fff3c10: 00009858 0000c4f5 40216ecc 3fff2c90
3fff3c20: 3fff4fe4 00000064 00000064 40213bff
3fff3c30: 000004ab 3fff4fdc 3fff5484 0000c4f5
3fff3c40: 00000000 3fff4fdc 3fff5484 402014ef
3fff3c50: 3fff24f0 3fff2b84 3fff2c90 3fff2b84
3fff3c60: 00000000 3fff2c7c 40216ecc 3fff2c90
3fff3c70: 40213c0a 000003e8 000003e8 3fff2c7c
3fff3c80: 3fffdad0 00000000 3fff2c74 4021532c
3fff3c90: feefeffe feefeffe 3fff2c74 40216f18
3fff3ca0: feefeffe feefeffe 3fff2c90 40100718
<<<stack<<<

markrad commented 7 years ago

I am unable to reproduce this issue even using Parson with no changes such as those detailed above. Can you install this tool https://github.com/me-no-dev/EspExceptionDecoder and provide me with a stack trace?

Mark Radbourne MSFT

markrad commented 7 years ago

This issue may be related to issue https://github.com/Azure/azure-iot-arduino/issues/46 where the incoming data is corrupted.

markrad commented 7 years ago

Hi @Patrik-Berglund,

A defect was found and addressed.

Mark Radbourne MSFT