Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions MKR1000-Azure.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(" %");

Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion time.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down