Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #define ONE_WIRE_BUS 8
- OneWire oneWire(ONE_WIRE_BUS);
- DallasTemperature sensors(&oneWire);
- #define SSID "SSID" //SSID of your wireless network
- #define PASS "PASSWORD" //Password of your wireless network
- #define IP "192.168.4.15" // Domoticz IP, be sure to also change on line #65! (Host: x.x.x.x)
- String GET = "GET /json.htm?type=command¶m=udevice&idx=109&nvalue=0&svalue=";
- long previousMillis = 0; // will store last time loop was executed
- // the follow variables is a long because the time, measured in miliseconds,
- // will quickly become a bigger number than can be stored in an int.
- long interval = 300000; // Interval for updating sensors (millisec), 300000 = 5 min = Domoticz virtual sensor interval
- void setup()
- {
- Serial.begin(9600);
- sensors.begin();
- Serial.println("AT");
- delay(5000);
- if(Serial.find("OK")){
- connectWiFi();
- }
- }
- void loop(){
- unsigned long currentMillis = millis();
- if(currentMillis - previousMillis > interval) {
- // save the last time you executed the actions
- previousMillis = currentMillis;
- // Perform actions
- sensors.requestTemperatures();
- float tempC = sensors.getTempCByIndex(0);
- //tempC = DallasTemperature::toFahrenheit(tempC);
- char buffer[10];
- String tempF = dtostrf(tempC, 4, 1, buffer);
- updateTemp(tempF);
- }
- }
- void updateTemp(String tempF){
- String cmd = "AT+CIPSTART=\"TCP\",\"";
- cmd += IP;
- cmd += "\",8080";
- Serial.println(cmd);
- delay(2000);
- if(Serial.find("Error")){
- return;
- }
- cmd = GET;
- cmd += tempF;
- cmd += " HTTP/1.1\r\n"; //construct http GET request
- cmd += "Host: 192.168.4.15\r\n\r\n"; //Change this IP to the IP-adress of your Domoticz
- Serial.print("AT+CIPSEND=");
- Serial.println(cmd.length());
- if(Serial.find(">")){
- Serial.print(cmd);
- }else{
- Serial.println("AT+CIPCLOSE");
- }
- }
- boolean connectWiFi(){
- Serial.println("AT+CWMODE=1");
- delay(2000);
- String cmd="AT+CWJAP=\"";
- cmd+=SSID;
- cmd+="\",\"";
- cmd+=PASS;
- cmd+="\"";
- Serial.println(cmd);
- delay(5000);
- if(Serial.find("OK")){
- return true;
- }else{
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement