her er for en WeMos (esp8266), så mesteparten skal vel sikkert fungere
du kan sikkert se bort fra det meste som har med DS18B20 og ESP8266 hvis dette skal brukes på en "normal" arduino
/*********
Rui Santos
Complete project details at http://randomnerdtutorials.com
*********/
// Including the ESP8266 WiFi library
#include <ESP8266WiFi.h> //mesteparten kan droppes hvis det ikke er til esp8266 eller ds18b20
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266HTTPClient.h>
// Data wire is plugged into pin D1 on the ESP8266 12-E - GPIO 5
#define ONE_WIRE_BUS 5
// Replace with your network details
const char* ssid = "DIN SSID";
const char* password = "DITT PASSORD";
String lastTemp;
IPAddress ip(192, 168, 1, 203); // IP-adresse til enheten
IPAddress subnet(255, 255, 255, 0);
IPAddress gateway(192, 168, 1, 1); //IP-adresse til Router
OneWire oneWire(ONE_WIRE_BUS); //OneWire
DallasTemperature DS18B20(&oneWire); //DS18B20
char temperatureCString[6];
// only runs once on boot
void setup() {
// Initializing serial port for debugging purposes
Serial.begin(115200);
delay(10);
DS18B20.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
// Connecting to WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.config(ip, gateway, subnet);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
String s = WiFi.macAddress();
Serial.println(s);
Serial.println(WiFi.macAddress());
// Printing the ESP IP address
Serial.println(WiFi.localIP());
}
float getTemperature() {
float tempC;
do {
DS18B20.requestTemperatures();
tempC = DS18B20.getTempCByIndex(0);
dtostrf(tempC, 2, 2, temperatureCString);
delay(100);
return readtemp
} while (tempC == 85.0 || tempC == (-127.0));
}
// runs over and over again
void loop() {
String stringTemp = String(getTemperature());
HTTPClient http;
if(stringTemp != lastTemp)
{
Serial.println("Temp endret");
Serial.println("Temp er:"+stringTemp+" Forrige var:"+lastTemp);
http.begin("http://192.168.1.6/JSON?request=controldevicebyvalue&ref=85&value="+stringTemp); // her skal JSON-strengen settes uinn
int httpCode = http.GET();
//http.writeToStream(&Serial);
http.end();
lastTemp = stringTemp;
delay(3000);
}
delay(30000); //Venter 30 sek før ny måling
det som befinner seg i "void loop" er det du er på jakt etter,