diff --git a/AZ3166/build_firmware/README.md b/AZ3166/build_firmware/README.md index 9369f11..7c241ad 100644 --- a/AZ3166/build_firmware/README.md +++ b/AZ3166/build_firmware/README.md @@ -6,6 +6,9 @@ that along with the example, please follow the steps below; Clone `devkit-sdk` into this folder. ``` git clone https://github.com/Microsoft/devkit-sdk +cd devkit-sdk +git checkout 0ca1b6ed8d06e7a2b371eb2c4e54ff61d6e3e899 +cd .. ``` Install [iotz](https://github.com/azure/iotz). You will need `Docker` and `node.js` (8+) is installed on your machine. diff --git a/AZ3166/inc/iotHubClient.h b/AZ3166/inc/AzureIOTClient.h similarity index 65% rename from AZ3166/inc/iotHubClient.h rename to AZ3166/inc/AzureIOTClient.h index 6057128..c7cd36b 100644 --- a/AZ3166/inc/iotHubClient.h +++ b/AZ3166/inc/AzureIOTClient.h @@ -1,18 +1,13 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. -#ifndef IOT_HUB_CLIENT_H -#define IOT_HUB_CLIENT_H +#ifndef AZURE_IOT_CLIENT_H +#define AZURE_IOT_CLIENT_H -typedef int (*hubDesiredCallback)(const char *, size_t, char **response, size_t* resp_size); -typedef void (*hubMethodCallback)(const char *, size_t); +typedef int (*hubMethodCallback)(const char *, size_t); #include - -typedef struct CALLBACK_LOOKUP_TAG_D { - char* name; - hubDesiredCallback callback; -} CALLBACK_LOOKUP_D; +#include "iotc.h" typedef struct CALLBACK_LOOKUP_TAG_M { char* name; @@ -32,49 +27,42 @@ struct DirectMethodNode DirectMethodNode *next; DirectMethodNode(): - methodName(NULL), payload(NULL), next(NULL), length(0) { } + methodName(NULL), payload(NULL), length(0), next(NULL) { } DirectMethodNode(char *m, char *p, size_t s): - methodName(m), payload(p), next(NULL), length(s) { } + methodName(m), payload(p), length(s), next(NULL) { } }; -class IoTHubClient +class AzureIOTClient { + IOTContext context; + bool hasError; - char deviceId[IOT_CENTRAL_MAX_LEN]; - char hubName[IOT_CENTRAL_MAX_LEN]; int displayCharPos; int waitCount; - bool needsCopying; - char displayHubName[AZ3166_DISPLAY_MAX_COLUMN + 1]; - IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle; - int trackingId; + char *deviceId; DirectMethodNode *rootNode, *lastNode; - void initIotHubClient(); - void closeIotHubClient(); + void init(); + void close(); public: - IoTHubClient(): hasError(false), displayCharPos(0), - waitCount(3), needsCopying(true), - iotHubClientHandle(NULL), trackingId(0), rootNode(NULL), - lastNode(NULL), methodCallbackCount(0), + AzureIOTClient(): context(NULL), hasError(false), displayCharPos(0), + rootNode(NULL), lastNode(NULL), methodCallbackCount(0), desiredCallbackCount(0), needsReconnect(false) { - memset(deviceId, 0, IOT_CENTRAL_MAX_LEN); - memset(hubName, 0, IOT_CENTRAL_MAX_LEN); - initIotHubClient(); + init(); } - ~IoTHubClient() + ~AzureIOTClient() { - closeIotHubClient(); + close(); } void hubClientYield(void) { checkConnection(); - IoTHubClient_LL_DoWork(iotHubClientHandle); + iotc_do_work(context); ThreadAPI_Sleep(1 /* waitTime */); } @@ -130,8 +118,8 @@ class IoTHubClient if (needsReconnect) { // simple reconnection of the client in the event of a disconnect LOG_VERBOSE("Reconnecting to the IoT Hub"); - closeIotHubClient(); - initIotHubClient(); + close(); + init(); needsReconnect = false; } @@ -141,15 +129,15 @@ class IoTHubClient bool sendReportedProperty(const char *payload); bool registerMethod(const char *methodName, hubMethodCallback callback); - bool registerDesiredProperty(const char *propertyName, hubDesiredCallback callback); + bool registerDesiredProperty(const char *propertyName, hubMethodCallback callback); void displayDeviceInfo(); // TODO: should this go under device? int methodCallbackCount; int desiredCallbackCount; CALLBACK_LOOKUP_M methodCallbackList[MAX_CALLBACK_COUNT]; - CALLBACK_LOOKUP_D desiredCallbackList[MAX_CALLBACK_COUNT]; + CALLBACK_LOOKUP_M desiredCallbackList[MAX_CALLBACK_COUNT]; bool needsReconnect; }; -#endif /* IOT_HUB_CLIENT_H */ \ No newline at end of file +#endif /* AZURE_IOT_CLIENT_H */ \ No newline at end of file diff --git a/AZ3166/inc/config.h b/AZ3166/inc/config.h index 2c790f6..8ca355b 100644 --- a/AZ3166/inc/config.h +++ b/AZ3166/inc/config.h @@ -20,7 +20,7 @@ class ConfigController { static void readWiFi(char* ssid, int ssidLen, char *password, int passwordLen); static void readConnectionString(char * connectionString, uint32_t buffer_size); static void readIotCentralConfig(char * iotCentralConfig, uint32_t buffer_size); - static void readGroupSXKeyAndDeviceId(char * scopeId, char * registrationId, char * sas, bool &sasKey); + static void readGroupSXKeyAndDeviceId(char * scopeId, char * registrationId, char * sas, char &atype); static void clearWiFiEEPROM(); static void clearAzureEEPROM(); diff --git a/AZ3166/inc/globals.h b/AZ3166/inc/globals.h index 7a3c832..36653fc 100644 --- a/AZ3166/inc/globals.h +++ b/AZ3166/inc/globals.h @@ -58,7 +58,6 @@ class LoopController; #define EMPTY_JSON "{}" struct Globals { - static const char * completedString; // "completed" static WiFiController wiFiController; static SensorController sensorController; static LoopController * loopController; @@ -76,7 +75,7 @@ struct Globals #define IOT_CENTRAL_ZONE_IDX 0x02 #define IOT_CENTRAL_MAX_LEN STRING_BUFFER_128 #define AZIOTC_FW_MAJOR_VERSION 2 -#define AZIOTC_FW_MINOR_VERSION 0 +#define AZIOTC_FW_MINOR_VERSION 1 #define AZIOTC_FW_PATCH_VERSION 0 #define AZIOTC_FW_VERSION TO_STRING(AZIOTC_FW_MAJOR_VERSION AZIOTC_FW_MINOR_VERSION AZIOTC_FW_PATCH_VERSION) "-MSIOTC" diff --git a/AZ3166/inc/httpHtmlData.h b/AZ3166/inc/httpHtmlData.h index 37f2648..337173f 100644 --- a/AZ3166/inc/httpHtmlData.h +++ b/AZ3166/inc/httpHtmlData.h @@ -11,14 +11,16 @@ charset=utf-8\r\nCache-Control: no-cache, no-store, \ must-revalidate\r\n\r\n" #define HTTP_HEADER_HTML HTTP_HEADER_NO_CACHE "\r\n Azure IoT Central Device Config " -#define HTTP_START_PAGE_HTML_ HTTP_HEADER_HTML "

Azure IoT Central Device Config

\ +#define HTTP_START_PAGE_HTML_ HTTP_HEADER_HTML "

Azure IoT Central Device Config

\ +
\
\
\
\
\
\
\ +required>
\
\ Setting the scope id is enough to authenticate with x509 option. \ This sample firmware already has the client cert builtin. Use \ @@ -42,15 +44,39 @@ class=\"primary\">Configure Device
Click \ refresh the page if you do not see your network
\