You are reading a single comment by @MaBe and its replies.
Click here to read the full conversation.
-
var settings_pol = 20; var settings_kondey = 24; var last_temp = 0; var temp_pol = 0; var dalas = setInterval(function() { require("DS18B20").connect(new OneWire(D13)).getTemp(function (temp) { print("Temp is "+temp+"°C"); if(temp!==null){ if(temp<settings_pol)digitalWrite(D14, true); if(temp>settings_pol)digitalWrite(D14, false); temp_pol = temp; } else digitalWrite(D14, false); }); }, 10000); function start_sensor(){ var dht_senso = setInterval(function() { require("DHT22").connect(D12).read(function (a) { print("Temp is "+a.temp.toString()+" and RH is "+a.rh.toString()); if(a.temp != -1){ if(a.temp>(settings_kondey+0.3))digitalWrite(D4, true); if(a.temp<settings_kondey)digitalWrite(D4, false); // if(a.temp!=last_temp){ setTimeout(function () { mqtt.publish("test", "{\"temp\":"+a.temp+",\"hum\":"+a.rh+",\"temp_pol\":"+temp_pol+",\"settings_kondey\":"+settings_kondey+",\"settings_pol\":"+settings_pol+"}");},1000); // last_temp = a.temp; // } }else digitalWrite(D4, false); }); }, 5000); } var server = "192.168.0.182"; // the ip of your MQTT broker var options = { // ALL OPTIONAL - the defaults are below client_id : "random", // the client ID sent to MQTT - it's a good idea to define your own static one based on `getSerial()` keep_alive: 60, // keep alive time in seconds port: 1883, // port number clean_session: true, //username: "home", // default is undefined //password: "789456", // default is undefined protocol_name: "MQTT", // or MQIsdp, etc.. protocol_level: 4, // protocol level }; var mqtt = require("MQTT").create(server, options /*optional*/); function reboot(){ print("reboot..."); ESP8266.reboot(); } var ESP8266 = require("ESP8266"), wifi = require("Wifi"); //var ssid = "Electrolux"; //var options = {password: "12345678"}; function onInit() { setTimeout(reboot,18000000); wifi.stopAP(); //wifi.startAP(ssid, options); //wifi.startAP("Electrolux"); // wifi.connect("INGRIFABSR", {password: "B73vFeX6se2"}, function(err) { wifi.connect("LP82K1", {password: "excitedboat325"}, function(err) { if(err)console.log(err);else { console.log("wifi connected!");//116 print(wifi.getIP().ip); mqtt.on('connected', function() { mqtt.subscribe("settings"); print("mqtt connected!"); start_sensor(); }); mqtt.on('publish', function (pub) { console.log("topic: "+pub.topic); console.log("message: "+pub.message); var settings=[]; if(pub.topic==="settings")settings = JSON.parse(pub.message); settings_pol = settings.settings_pol; settings_kondey = settings.settings_kondey; }); mqtt.connect(); mqtt.on('disconnected', function() { console.log("MQTT disconnected... reconnecting."); setTimeout(function() { mqtt.connect(); }, 10000); }); } }); }
Hi @user79559,
Please share what you try to achieve, so someone might point you to documents or code snippets to support you.