Kjører koden til Miles Burton og deg:
---
/*
Created by Miles Burton
Created by Morten G. Sevland - Bjørnheim Bryggeri - Website: sevland.no
External libraries:
https://github.com/milesburton/Arduino-Temperature-Control-Library
*/
#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// ****** WiFi settings / AP definitions
#define AP_SSID " - - - "
#define AP_PASSWORD " - - - "
// Cloud definitions / Thingspeak API key ******
String apiKey = " - - - "; // Insert your Write API Key from ThingSpeak.com
#define REPORT_INTERVAL 60 // in sec
#define ThingSpeak_CLOUD_PORT 80
const char* ThingSpeak_CLOUD_ADDRESS = "api.thingspeak.com";
// ****** DS18B20 and Temperature settings ******
#define ONE_WIRE_BUS 2 // DS18B20 pin to GPIO2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20_Sensors(&oneWire);
void setup() {
Serial.begin(115200);
DS18B20_Sensors.begin(); // Start up the sensors library
wifiConnect();
}
void loop() {
WiFiClient client;
DS18B20_Sensors.requestTemperatures();
delay(100);
float temp;
temp = DS18B20_Sensors.getTempCByIndex(0);
// First check if connected, then send sensordata for the right number of devices
if (client.connect(ThingSpeak_CLOUD_ADDRESS,ThingSpeak_CLOUD_PORT)) {
String postStr = apiKey;
postStr +="&field1=";
postStr += String(temp);
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.println("");
Serial.print("Temp: ");
Serial.println(temp);
Serial.print("Send to Thingspeak");
}
client.stop();
// *********** Countdown *************
int cnt = (REPORT_INTERVAL);
while(cnt--)
delay(100);
}
void wifiConnect()
{
Serial.print("Connecting to AP");
WiFi.begin(AP_SSID, AP_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
---
(EDIT: fjerna SSID, passord og Thingspeak API-key, hehe)