From 4800eb73e68c96e8ad536ed4ca5785924fd2e226 Mon Sep 17 00:00:00 2001 From: Mimsseey <56138496+Mimsseey@users.noreply.github.com> Date: Wed, 27 Nov 2019 08:54:04 +0100 Subject: [PATCH 1/3] Update MKR1000-Azure.ino --- MKR1000-Azure.ino | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/MKR1000-Azure.ino b/MKR1000-Azure.ino index e8dd1da..933aa61 100644 --- a/MKR1000-Azure.ino +++ b/MKR1000-Azure.ino @@ -16,12 +16,13 @@ RTCZero rtc; DHT dht(DHTPIN, DHTTYPE); // Generate SAS key using https://github.com/sandrinodimattia/RedDog/releases +// For IoT Hub use Device Explorer from Azure SDK git repo char hostname[] = "connectthedotsex-ns.servicebus.windows.net"; char authSAS[] = "SharedAccessSignature sr=https%3a%2f%2fconnectthedotsex-ns.servicebus.windows.net%2fehdevices%2fpublishers%2fd1%2fmessages&sig=OzFhN9z3ROSBqmaEz1em3DHIPsj7vcu3gY4BE60n%2fTo%3d&se=1460172816&skn=D1"; String hubName = "ehdevices"; String deviceName = "D1"; -String uri = "/" + hubName + "/publishers/" + deviceName + "/messages"; +String uri = "/" + hubName + "/publishers/" + deviceName + "/messages/methods?api-version=2018-06-30" int status = WL_IDLE_STATUS; WiFiSSLClient client; @@ -55,11 +56,11 @@ void setup() { } void loop() { - float temperature = dht.readTemperature(true); // true == Fahrenheit + float temperature = dht.readTemperature(); // true == Fahrenheit, otherwise leave empty for °C float humidity = dht.readHumidity(); Serial.print(temperature); - Serial.print(" *F "); + Serial.print(" °C "); Serial.print(humidity); Serial.println(" %"); @@ -102,8 +103,9 @@ String createJSON(String measurename, float value, String unitofmeasure) { // JSON is based on Microsoft Connect the Dots example // https://github.com/Azure/connectthedots/blob/master/Introduction.md#device-basics - StaticJsonBuffer<200> jsonBuffer; - JsonObject& root = jsonBuffer.createObject(); + // Changes since JSON V5 JsonBuffer and JsonObject now StaticJsonDOcument + StaticJsonDocument<200> doc; + JsonObject root = doc.createNestedObject(); root["subject"] = "wthr"; root["organization"] = "Foo Industries"; root["displayname"] = "MKR1000"; @@ -114,7 +116,7 @@ String createJSON(String measurename, float value, String unitofmeasure) { root["guid"] = "123456"; char json[200]; - root.printTo(json, sizeof(json)); + root.printTo(doc, json, sizeof(json)); return String(json); } From 02953718c3ef279354295796a836fe4641bb7514 Mon Sep 17 00:00:00 2001 From: Mimsseey <56138496+Mimsseey@users.noreply.github.com> Date: Wed, 27 Nov 2019 08:59:05 +0100 Subject: [PATCH 2/3] Update time.cpp --- time.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/time.cpp b/time.cpp index 5e80f7b..5dd0b2a 100644 --- a/time.cpp +++ b/time.cpp @@ -1,7 +1,7 @@ #include "time.h" unsigned int localPort = 2390; // local port to listen for UDP packets -IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server +IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server IP Adrress find nearest NTP via pool.ntp.org const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets WiFiUDP Udp; // A UDP instance to let us send and receive packets over UDP From 3f93bcac9a64d77bf0a833e25bd50009f6140808 Mon Sep 17 00:00:00 2001 From: Mimsseey <56138496+Mimsseey@users.noreply.github.com> Date: Sat, 30 Nov 2019 18:12:16 +0100 Subject: [PATCH 3/3] Update MKR1000-Azure.ino --- MKR1000-Azure.ino | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/MKR1000-Azure.ino b/MKR1000-Azure.ino index 933aa61..fdecf72 100644 --- a/MKR1000-Azure.ino +++ b/MKR1000-Azure.ino @@ -22,7 +22,7 @@ char authSAS[] = "SharedAccessSignature sr=https%3a%2f%2fconnectthedotsex-ns.ser String hubName = "ehdevices"; String deviceName = "D1"; -String uri = "/" + hubName + "/publishers/" + deviceName + "/messages/methods?api-version=2018-06-30" +String uri = "/" + hubName + "/publishers/" + deviceName + "/messages/methods?api-version=2018-06-30"; int status = WL_IDLE_STATUS; WiFiSSLClient client; @@ -104,19 +104,17 @@ String createJSON(String measurename, float value, String unitofmeasure) { // JSON is based on Microsoft Connect the Dots example // https://github.com/Azure/connectthedots/blob/master/Introduction.md#device-basics // Changes since JSON V5 JsonBuffer and JsonObject now StaticJsonDOcument - StaticJsonDocument<200> doc; - JsonObject root = doc.createNestedObject(); - root["subject"] = "wthr"; - root["organization"] = "Foo Industries"; - root["displayname"] = "MKR1000"; - root["measurename"] = measurename; - root["unitofmeasure"] = unitofmeasure; - root["value"] = String(value); - root["timecreated"] = dateString; - root["guid"] = "123456"; + StaticJsonDocument<200> doc; //Static Json Document with size of 200 KB + doc["subject"] = "wthr"; //add variables to doc + doc["displayname"] = "MKR1000"; + doc["measurename"] = measurename; + doc["unitofmeasure"] = unitofmeasure; + doc["value"] = String(value); + doc["timecreated"] = dateString; + doc["guid"] = "123456"; char json[200]; - root.printTo(doc, json, sizeof(json)); + serializeJson(doc, Serial); return String(json); }