Sarah SextonPaul DeCarlo
Published © GPL3+

Hands-on-Lab Particle Core Weather Station in Azure

This example demonstrates how to leverage Particle Core and Microsoft Azure to create a weather station using the DHT11 sensor.

BeginnerFull instructions provided3,399
Hands-on-Lab Particle Core Weather Station in Azure

Things used in this project

Hardware components

Spark Core
Particle Spark Core
×1
Solderless Female to Female Jumper Wires
×3
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1

Software apps and online services

Microsoft Azure
Microsoft Azure

Story

Read more

Schematics

Schematics

The final assembly of the Particle Core and the DHT11 sensor.

Code

webhook.json

JSON
{ 
 "event": "ConnectTheDots", 
 "url": "https://connectthedotsex-ns.servicebus.windows.net/ehdevices/messages", 
 "requestType": "POST", 
 "json": { 
 "subject": "{{s}}", 
 "unitofmeasure": "{{u}}", 
 "measurename": "{{m}}", 
 "value": "{{v}}", 
 "organization": "{{o}}", 
 "displayname": "{{d}}", 
 "location": "{{l}}", 
 "timecreated": "{{SPARK_PUBLISHED_AT}}", 
 "guid": "{{SPARK_CORE_ID}}"

},

 "azure_sas_token": { 
 "key_name": "D1", 
 "key": "mBLQGWxSkRHg7f2eRCLonHUpNS+DY0iPHclxjf7Cmvk=" 
 }, 
 "mydevices": true 
}

ParticleWeatherShield code

C/C++
// This #include statement was automatically added by the Spark IDE.
#include "Adafruit_DHT/Adafruit_DHT.h"

#define DHTPIN 2    // what pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11		// DHT 11 
//#define DHTTYPE DHT22		// DHT 22 (AM2302)
//#define DHTTYPE DHT21		// DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

char Org[] = "ORGANIZATION_NAME";
char Disp[] = "DISPLAY_NAME";
char Locn[] = "LOCATION";


void setup()
{
    dht.begin();
    delay(10000);
}

 
void loop()
{
    delay(5000);
    
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a 
// very slow sensor)
	float h = dht.getHumidity();
// Read temperature as Celsius
    float t = dht.getTempCelcius();
// Read temperature as Farenheit
	float f = dht.getTempFarenheit();
  
// Check if any reads failed and exit early (to try again).
//	if (isnan(h) || isnan(t) || isnan(f)) {
//		Serial.println("Failed to read from DHT sensor!");
//		return;
//	}   
   
    char payload[255];
    
    snprintf(payload, sizeof(payload), "{ \"s\":\"wthr\", \"u\":\"F\",\"l\":\"%s\",\"m\":\"Temperature\",\"o\":\"%s\",\"v\": %f,\"d\":\"%s\" }", Locn, Org, f, Disp);
    Spark.publish("ConnectTheDots", payload);
    
    delay(5000);
    
    snprintf(payload, sizeof(payload), "{ \"s\":\"wthr\", \"u\":\"%%\",\"l\":\"%s\",\"m\":\"Humidity\",\"o\":\"%s\",\"v\": %f,\"d\":\"%s\" }", Locn, Org, h, Disp);
    Spark.publish("ConnectTheDots", payload);
    
}

Credits

Sarah Sexton

Sarah Sexton

1 project • 2 followers
Microsoft Technical Evangelist, Unity Indie Game Developer, SheBuildsGames blogger, Voxelles: Women in Game Development Co-Founder
Paul DeCarlo

Paul DeCarlo

7 projects • 221 followers
Paul DeCarlo is a prof @ #Bauer college of Business @UniversityOfHouston and Software Engineer @Microsoft focused on IoT, Cloud, and Mobile.
Thanks to Paul DeCarlo.

Comments