Nevím si rady se zprovozněním esp a jednoho ds18b20 tak, aby data odesílal na wunderground. S thingspeak to není problém, ale tohle jsem nikde nenašel. Jak upravit např. tento kód, aby odesílal data na wunderground? Díky
Kód: Vybrat vše
#include <DallasTemperature.h>
#include <OneWire.h>
#include <ThingSpeak.h>
#include <ESP8266WiFi.h>
// User changeable vaules go here.
#define ONE_WIRE_BUS D4 // Digital pin DS18B20 is connected to.
#define TEMPERATURE_PRECISION 11 // Set sensor precision. Valid options 8,10,11,12 Lower is faster but less precise
unsigned long myChannelNumber = 123456; // Thingspeak channel ID here
const char * myWriteAPIKey = "YOUR_API_WRITE_KEY"; // Write API key here
const char* ssid = "WIRELESS_SSID"; // SSID of wireless network
const char* password = "WIRELESS_PASSWORD"; // Password for wireless network
int fieldStart = 1; // Field number to start populating ThingSpeak channel data, leave at
// 1 if this is the only device reporting to that channel.
// If more than one device this should be the FIRST FREE field.
int updatePeriod = 300; //delay in seconds to update to ThingSpeak. Should be set to not less than 15.
int status = WL_IDLE_STATUS;
WiFiClient client;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int numberOfDevices; // Number of temperature devices found
DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address
void setup() {
Serial.begin(115200);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
ThingSpeak.begin(client);
sensors.begin();
// Grab a count of devices on the wire
numberOfDevices = sensors.getDeviceCount();
// locate devices on the bus
Serial.print("Locating devices...");
Serial.print("Found ");
Serial.print(numberOfDevices, DEC);
Serial.println(" devices.");
// report parasite power requirements
Serial.print("Parasite power is: ");
if (sensors.isParasitePowerMode()) Serial.println("ON");
else Serial.println("OFF");
// Loop through each device, print out address
for(int i=0;i<numberOfDevices; i++)
{
// Search the wire for address
if(sensors.getAddress(tempDeviceAddress, i))
{
Serial.print("Found device ");
Serial.print(i, DEC);
Serial.print(" with address: ");
printAddress(tempDeviceAddress);
Serial.println();
Serial.print("Setting resolution to ");
Serial.println(TEMPERATURE_PRECISION, DEC);
// set the resolution to TEMPERATURE_PRECISION bit (Each Dallas/Maxim device is capable of several different resolutions)
sensors.setResolution(tempDeviceAddress, TEMPERATURE_PRECISION);
Serial.print("Resolution actually set to: ");
Serial.print(sensors.getResolution(tempDeviceAddress), DEC);
Serial.println();
}else{
Serial.print("Found ghost device at ");
Serial.print(i, DEC);
Serial.print(" but could not detect address. Check power and cabling");
}
}
}
// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
for (uint8_t i = 0; i < 8; i++)
{
if (deviceAddress[i] < 16) Serial.print("0");
Serial.print(deviceAddress[i], HEX);
}
}
void loop() {
sensors.requestTemperatures();
// Itterate through each sensor and send readings to ThinkSpeak.
for (int i=0; i<=(numberOfDevices - 1); i++){
float temp=sensors.getTempCByIndex(i);
ThingSpeak.setField(i+fieldStart,temp);
Serial.println("Sensor #:");
Serial.println(i);
Serial.println("Temperature:");
Serial.println(temp);
}
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); //Write fields to Thingspeak, comment this line out
//if you wish to test without uploading data.
Serial.println("Data sent to ThinkSpeak");
delay(updatePeriod * 1000);
}