I have made several attempts to use this library on my ESP8266 module with no luck. Microsoft has stated that this repo should work with the ESP8266 module. At first it did not work at all. I was able to get it running by turning off logging. Now it will run for a while but eventually begins to throw an exception. (It usually takes upwards of 30 min before I get the exception)
iothub_client_sample_device_twin.c
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include <stdio.h>
#include <stdlib.h>
#include "iot_configs.h"
#include "sample.h"
#include <AzureIoTHub.h>
#include <AzureIoTProtocol_MQTT.h>
/*String containing Hostname, Device Id & Device Key in one of the formats: */
/* "HostName=<host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>" */
/* "HostName=<host_name>;DeviceId=<device_id>;SharedAccessSignature=<device_sas_token>" */
static const char* connectionString = IOT_CONFIG_CONNECTION_STRING;
static char msgText[1024];
static char propText[1024];
static bool g_continueRunning;
#define DOWORK_LOOP_NUM 100
static void deviceTwinCallback(DEVICE_TWIN_UPDATE_STATE update_state, const unsigned char* payLoad, size_t size, void* userContextCallback)
{
(void)userContextCallback;
printf("Device Twin update received (state=%s, size=%u): \r\n",
ENUM_TO_STRING(DEVICE_TWIN_UPDATE_STATE, update_state), size);
for (size_t n = 0; n < size; n++)
{
// printf("%c", payLoad[n]);
}
printf("\r\n");
}
static void reportedStateCallback(int status_code, void* userContextCallback)
{
(void)userContextCallback;
printf("Device Twin reported properties update completed with result: %d\r\n", status_code);
g_continueRunning = false;
}
void iothub_client_sample_device_twin_run(void)
{
// Result checks are omitted to simplify the sample.
// Please verify all returns on your production code.
IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle;
g_continueRunning = true;
IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol = MQTT_Protocol;
if (platform_init() != 0)
{
(void)printf("Failed to initialize the platform.\r\n");
}
else
{
if ((iotHubClientHandle = IoTHubClient_LL_CreateFromConnectionString(connectionString, protocol)) == NULL)
{
(void)printf("ERROR: iotHubClientHandle is NULL!\r\n");
}
else
{
bool traceOn = false;
// This json-format reportedState is created as a string for simplicity. In a real application
// this would likely be done with parson (which the Azure IoT SDK uses) or a similar tool.
const char* reportedState = "{ 'device_property': 'new_value'}";
size_t reportedStateSize = strlen(reportedState);
(void)IoTHubClient_LL_SetOption(iotHubClientHandle, OPTION_LOG_TRACE, &traceOn);
(void)IoTHubClient_LL_SetDeviceTwinCallback(iotHubClientHandle, deviceTwinCallback, iotHubClientHandle);
(void)IoTHubClient_LL_SendReportedState(iotHubClientHandle, (const unsigned char*)reportedState, reportedStateSize, reportedStateCallback, iotHubClientHandle);
do
{
IoTHubClient_LL_DoWork(iotHubClientHandle);
ThreadAPI_Sleep(100);
} while (g_continueRunning);
for (size_t index = 0; index < DOWORK_LOOP_NUM; index++)
{
IoTHubClient_LL_DoWork(iotHubClientHandle);
ThreadAPI_Sleep(100);
}
// LogInfo("IoTHubClient_LL_Destroy starting");
IoTHubClient_LL_Destroy(iotHubClientHandle);
// LogInfo("IoTHubClient_LL_Destroy okay");
}
platform_deinit();
}
}
void sample_run(void)
{
iothub_client_sample_device_twin_run();
}
Logs
Attempting to connect to SSID: ******
scandone
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 5
cnt
connected with *******, channel 5
dhcp client start...
.ip:1.1.1.1,mask:1.1.1.1,gw:1.1.1.1
.
Connected to wifi
Fetching NTP epoch time failed! Waiting 2 seconds to retry.
Fetched NTP epoch time is: 1533994630
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Device Twin update received (state=DEVICE_TWIN_UPDATE_COMPLETE, size=341):
Device Twin reported properties update completed with result: 204
Fatal exception 3(LoadStoreErrorCause):
epc1=0x4000bf64, epc2=0x00000000, epc3=0x00000000, excvaddr=0x402561f3, depc=0x00000000
Exception (3):
epc1=0x4000bf64 epc2=0x00000000 epc3=0x00000000 excvaddr=0x402561f3 depc=0x00000000
ctx: cont
sp: 3fff1c20 end: 3fff2000 offset: 01a0
>>>stack>>>
3fff1dc0: 3fff0f8c 000002ae 000002ae 4010020c
3fff1dd0: 401050ef 00000053 3fff3a94 40100690
3fff1de0: 00000000 00000000 00000090 4020fda4
3fff1df0: 3fff0d3c 00000053 3fff3dec 4020ed8b
3fff1e00: 3fff8324 3fff5f34 3fff3a94 402100fc
3fff1e10: 00000053 00000000 3fff0d54 4020f5cc
3fff1e20: 3fff3dec 3fff3a94 000008ca 3fff2f14
3fff1e30: 3fff0d3c 00000053 00000000 4020f70d
3fff1e40: 00000000 00000000 00000d06 40206bd9
3fff1e50: 3fff1e70 40206532 00000171 3fff5f34
3fff1e60: 4020a800 000067d8 00000cfb 3fff2f14
3fff1e70: 402561f3 3fff3a90 ffff8000 000000ae
3fff1e80: 3fff61a8 00000686 3fff7b6c 40206523
3fff1e90: 00000000 008f4000 3fff7b6c 00000053
3fff1ea0: 3fff5f34 3fff2f14 3fff2f14 4020db89
3fff1eb0: 3fff5f34 3fff2f14 3fff2f14 4020aa15
3fff1ec0: 3fff6b4c 0000002e 00000000 40206f52
3fff1ed0: 0000002f 3fff1ee0 00000004 3fff7b6c
3fff1ee0: 00000000 3fff2f14 00000053 4020b5bd
3fff1ef0: 00000021 00000000 3fff7b0c 4020c60e
3fff1f00: 00000004 00000000 00000000 00000000
3fff1f10: 00000000 3fff3bcc 3fff8fd4 3fff3d54
3fff1f20: 3fff7b44 3fff74cc 3fff8fd4 40205265
3fff1f30: 3fff8ff0 3fff3b54 00000004 401004d8
3fff1f40: 3fff6fe4 008f4000 3fff336c 3fff6fec
3fff1f50: 3fff6198 3fff6184 3fff6fe4 40205f74
3fff1f60: 3fff0d38 00000000 3fff6fe4 4020179c
3fff1f70: 3fff6184 3fff0fd8 4020fe6c 3fff0fe0
3fff1f80: 3fff6fec 00000064 00000064 4020cbb3
3fff1f90: 3ffea1e3 00000000 3fff6fe4 3fff0fd8
3fff1fa0: 3fff0d38 00000000 3fff6fe4 40201100
3fff1fb0: 3ffea100 5b6ee686 3fff0fac 4020de68
3fff1fc0: 3fffdad0 00000000 3fff0fd0 40201140
3fff1fd0: 00000000 00000000 00000001 4020dc64
3fff1fe0: 3fffdad0 00000000 3fff0fd0 4020feb8
3fff1ff0: feefeffe feefeffe 3fff0fe0 40100710
<<<stack<<<
User contributions licensed under CC BY-SA 3.0