Quantcast
Channel: ThingSpeak IoT Community - Forum: Arduino
Viewing all articles
Browse latest Browse all 172

wheato22 on updating multiple fields to thingspeak

$
0
0

sushma said

hello,
actually i m using 4 fields in a channel. in that i have used first field for updating the moisture sensor data and i wann use fields 2,3,4 for updating dht11 sensor data i.e field 2 for temperature , field 3 for humidity, and field 4 for dew points. but i m not able update all the 4 fields at a time though i have multiple fields in channel setting, just the field 1 is getting updated.

---------------------
Hi,
Here is sample code from a Kickstarter project that shows a way update multiple fields with one write. It worked for me on my water meter project.
Larry

// This #include statement was automatically added by the Particle IDE.
#include "ThingSpeak.h"

// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_DHT/Adafruit_DHT.h"

// Sensor type
#define DHTTYPE DHT22 // DHT 22 (AM2302)

// DHT22 sensor pinout:
// Pin 1 (on the left): +3.3V
// Pin 2: output
// Pin 4 (on the right): GROUND
#define DHT_5V_PIN D1
#define DHT_SENSOR_PIN D2
#define DHT_GROUND_PIN D4

DHT dht(DHT_SENSOR_PIN, DHTTYPE);

/* Thingspeak */
TCPClient client;
unsigned long myChannelNumber = 89137;
const char * myWriteAPIKey = "3D23PQHQIJ3OZXNF";

void setup() {
// Connect to ThingSpeak
ThingSpeak.begin(client);

// Give power to the sensor
pinMode(DHT_5V_PIN, OUTPUT);
pinMode(DHT_GROUND_PIN, OUTPUT);
digitalWrite(DHT_5V_PIN, HIGH);
digitalWrite(DHT_GROUND_PIN, LOW);

// Wait for the sensor to stabilize
delay(1000);

// Initialize sensor
dht.begin();

// Read Sensor
double temperature = dht.getTempCelcius();
double humidity = dht.getHumidity();

// Update the 2 ThingSpeak fields with the new data
ThingSpeak.setField(1, (float)temperature);
ThingSpeak.setField(2, (float)humidity);

// Write the fields that you've set all at once.
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);

// Give time for the message to reach ThingSpeak
delay(5000);

// Sleep for 15 minutes to save battery
System.sleep(SLEEP_MODE_DEEP, 15 * 60);
}

void loop() {
// This will run because the system is sleeping
}


Viewing all articles
Browse latest Browse all 172

Trending Articles