diff --git a/MKR1000-Azure.ino b/MKR1000-Azure.ino index e8dd1da..fdecf72 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,19 +103,18 @@ 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(); - 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"; + // Changes since JSON V5 JsonBuffer and JsonObject now StaticJsonDOcument + 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(json, sizeof(json)); + serializeJson(doc, Serial); return String(json); } 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