Skip to content

Instantly share code, notes, and snippets.

@SibeeshVenu
Last active January 14, 2019 10:04
Show Gist options
  • Save SibeeshVenu/6529a57c8c43dc27e3b8df77b0e849fc to your computer and use it in GitHub Desktop.
Save SibeeshVenu/6529a57c8c43dc27e3b8df77b0e849fc to your computer and use it in GitHub Desktop.
//Configuration functions - Start//
static void initWifi()
{
Screen.print(2, "Connecting...");
if (WiFi.begin() == WL_CONNECTED)
{
IPAddress ip = WiFi.localIP();
Screen.print(1, ip.get_address());
hasWifi = true;
Screen.print(2, "Running... \r\n");
}
else
{
hasWifi = false;
Screen.print(1, "No Wi-Fi\r\n ");
}
}
static void sendConfirmationCallback(IOTHUB_CLIENT_CONFIRMATION_RESULT result)
{
if (result == IOTHUB_CLIENT_CONFIRMATION_OK)
{
blinkSendConfirmation();
}
}
static void messageCallback(const char *payLoad, int size)
{
blinkLED();
Screen.print(1, payLoad, true);
}
static void deviceTwinCallback(DEVICE_TWIN_UPDATE_STATE updateState, const unsigned char *payLoad, int size)
{
char *temp = (char *)malloc(size + 1);
if (temp == NULL)
{
return;
}
memcpy(temp, payLoad, size);
temp[size] = '\0';
parseTwinMessage(updateState, temp);
free(temp);
}
static int deviceMethodCallback(const char *methodName, const unsigned char *payload, int size, unsigned char **response, int *response_size)
{
LogInfo("Try to invoke method %s", methodName);
const char *responseMessage = "\"Successfully invoke device method\"";
int result = 200;
if (strcmp(methodName, DIRECT_METHOD_NAME) == 0)
{
messageReceived = true;
char *temp = (char *)malloc(size + 1);
memcpy(temp, payload, size);
temp[size] = '\0';
if (temp != NULL)
{
Screen.init();
Screen.print(0, "NEW MESSAGE!");
Screen.print(2, temp);
}
free(temp);
}
else
{
LogInfo("No method %s found", methodName);
responseMessage = "\"No method found\"";
result = 404;
}
*response_size = strlen(responseMessage);
*response = (unsigned char *)malloc(*response_size);
strncpy((char *)(*response), responseMessage, *response_size);
return result;
}
//Configuration functions - End//
//***********************************//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment