The purpose of this project is to provide simple directions on how to send data (temperature & humidity) from Particle Photon to ThingSpeak without using Webhook.
Requirements- Particle Photon
- DHT22 sensor, Resistor
- Particle.io Build Account
- ThingSpeak User Account
You should be familiar with Particle build IDE, article will not go into step-by-step tutorial how to flash Particle Photon.
HardwareSchematic is very simple. Connect DHT22 data pin with Particle Photon D2. Add pull-up resistor between Vdd and data pin. Finnaly, connect DHT22 pins VDD and Ground with 3V3 and GND pins on Photon... that's all.
ThingSpeak DashboardFor ThingSpeak you should understand some important terms. ThingSpeak channels store data sent to them from device. Each channel has unique ID. If your application need to send data, you have to provide Write API Key. Each channel has 8 fields for storing separated values. In our case, we use two fields : Temp and Humid. Next two screenshots will help to configure ThingSpeak channel:
Software
Full code is attached with this article, but important lines are shown below with some explanations.
- Create TCPclient
TCPClient client;
- Add your Thingspeak ChannelNumber (ChannelID)
- Add your Thingspeak WriteAPIKey
unsigned int myChannelNumber = xxxxxx; // replace with your ChannelID
const char * myWriteAPIKey = "xxxxx"; // replace with your WriteAPIKey
- In setup procedure start ThingSpeak client
ThingSpeak.begin(client);
- Get data from DHT22 sensor
- Store values in field1 and field2
float h = dht.getHumidity();
float t = dht.getTempCelcius();
ThingSpeak.setField(1,t);
ThingSpeak.setField(2,h);
- Send data to ThingSpeak channel
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
Ready?Last step is flashing code into Particle Photon. Sign in ThingSpeak and wait for incoming data.
Final Screenshot
Comments