Azure-Samples / iot-hub-c-m0wifi-getstartedkit

Get started with the Adafruit Feather M0 Wifi Azure IoT Starter Kit
MIT License
5 stars 8 forks source link

Receive commands only once, and only one #45

Closed gmhewett closed 7 years ago

gmhewett commented 7 years ago

Hi,

I am using the remote monitoring solution and an Arduino M0 feather. When using the HTTP protocol to send messages from the Arduino to IoTHub, everything works great. However, I can only receive one command per startup. After that, the IoTHubClient_LL_DoWork function is called, but no command is processed.

The code in question from remote_moitoring.c:

            sendMessage(iotHubClientHandle, buffer, bufferSize);
        }
    }

IoTHubClient_LL_DoWork(iotHubClientHandle);
ThreadAPI_Sleep(1000);
currentCycle++;

The first time IoTHubClient_LL_DoWork(iotHubClientHandle) is called, it processes one command, and one command only, even if more are in the queue. I've modified iothub_client_ll.c to log what's happing, and the IoTHubClient_LL_DoWork(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle) appears to be working fine, so I'm not sure what's going on.

Any help would be appreciated. Thanks!

GregTerrell commented 7 years ago

As I recall the example remote monitoring example only does one sample and likewise one command. You will need to create a loop. The work of sending the serialized sample and of processing the incoming command are both done within IoTHubClient_LL_DoWork().

gmhewett commented 7 years ago

@GregTerrell thanks for responding. I figured out what my issue was: I was using HTTP protocol to send/receive messages, and the SDK only checks for commands every 25 minutes or so, as per current HTTP guidelines. So, even though my while loop was calling dowork, there was no work to be done because the client hadn't polled the IoT Hub yet. Unfortunately, MQTT is not currently working on the Arduino Feather M0, though. Thanks!