Created
December 28, 2014 21:42
-
-
Save stlehmann/0f4645fe9cbfff3f5cf4 to your computer and use it in GitHub Desktop.
Read Temperature from onewire sensor end send to Thingspeak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <OneWire.h> | |
#include <DallasTemperature.h> | |
#include <uartWIFI.h> | |
#define SSID "my_network" | |
#define PASS "my_password" | |
#define ONEWIRE_BUS 10 | |
#define THINGSPEAK_IP "184.106.153.149" | |
#define THINGSPEAK_KEY "my_thingspeak_key" | |
#define MINUTES 10 | |
String GET = "GET http://api.thingspeak.com/update?key=" + String(THINGSPEAK_KEY) + "&field1="; | |
WIFI wifi; | |
OneWire onewire(ONEWIRE_BUS); | |
DallasTemperature sensors(&onewire); | |
void setup(void) | |
{ | |
delay(1000); | |
while (!wifi.begin()) | |
{ | |
DebugSerial.println("Begin error"); | |
} | |
while (!wifi.Initialize(STA, SSID, PASS)) | |
{ | |
delay(1000); | |
DebugSerial.println("Init error"); | |
} | |
sensors.begin(); | |
sensors.setWaitForConversion(true); | |
delay(1000); | |
} | |
void loop(void) | |
{ | |
//Read temperature from 1W-Sensor | |
DebugSerial.print("Requesting temperatures..."); | |
sensors.requestTemperatures(); | |
Serial.println("Done"); | |
Serial.print("Temperature for device 1 is: "); | |
float temp = sensors.getTempCByIndex(0); | |
Serial.println(temp); | |
//Connect to Thingspeak | |
wifi.newMux(TCP, THINGSPEAK_IP, 80); | |
//Send current temperature | |
char s[10]; | |
String cmd = GET; | |
cmd += dtostrf(temp, 2, 2, s); | |
cmd += "\r\n"; | |
wifi.Send(cmd); | |
//Wait for a couple of minutes | |
for (int i=0; i<MINUTES; i++) | |
delay(60000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment