Facebook
From Smelly Coyote, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 213
  1.  
  2. #define BLYNK_PRINT Serial
  3. #include <ESP8266WiFi.h>
  4. #include <BlynkSimpleEsp8266.h>
  5.  
  6.  
  7. /***************************/
  8.  
  9. #include <LiquidCrystal_I2C.h> // wyswietlacz
  10. #include <OneWire.h> //
  11. #include <DallasTemperature.h> //czyujnik temp
  12. #include <Wire.h>
  13.  
  14. String apiKey = "";     //  Enter your Write API key from ThingSpeak
  15. char auth[] = "";
  16. const char *ssid =  "";     // replace with your wifi ssid and wpa2 key
  17. const char *pass =  "";
  18. const char* server = "api.thingspeak.com";
  19.  
  20.  
  21.  
  22. WiFiClient client;
  23. BlynkTimer timer;
  24.  
  25. #define przekaznik D1
  26.  
  27. LiquidCrystal_I2C lcd(0x27,16,2); //wyswietlacz
  28. OneWire oneWire(D2 );
  29. DallasTemperature sensors(&oneWire);
  30.  
  31.  
  32. int counter = 25; // poczatkowa temp.
  33. bool bPress = false;
  34.  
  35. unsigned long timeStart = 0;
  36.  
  37.  
  38.  
  39. bool isCounting = false;
  40.  
  41. int CalcSt = 30 ;
  42.  
  43. float x = 0;
  44. const int Up = D7;
  45. const int Down = D8;
  46. int upbutt = 0;
  47. int uplastbutt = 0;
  48. int downbutt = 0;
  49. int downlastbutt = 0;
  50.  
  51. void setup(){
  52.  
  53.  
  54.   Wire.begin(D5,D6);
  55.   lcd.begin();
  56.   lcd.clear();
  57.   lcd.setCursor(0,0); // napis u gory
  58.   lcd.print("Ustaw temp: ");
  59.   lcd.print(counter);
  60.   lcd.setCursor(0,1); // napis na dole
  61.   lcd.print("T:00.00*C");
  62.  
  63.   sensors.begin();
  64.    pinMode(przekaznik, OUTPUT);
  65.   pinMode(Up, INPUT_PULLUP);
  66.   pinMode(Down, INPUT_PULLUP);
  67.   timeStart=millis();
  68.   isCounting = true;
  69.  
  70.   //////////
  71.  
  72.        Serial.begin(115200);
  73.        delay(10);
  74.        
  75.  
  76.        Serial.println("Connecting to ");
  77.        Serial.println(ssid);
  78.  
  79.  
  80.        WiFi.begin(ssid, pass);
  81.  
  82.       while (WiFi.status() != WL_CONNECTED)
  83.      {
  84.             delay(500);
  85.             Serial.print(".");
  86.      }
  87.  
  88.       Serial.println("");
  89.       Serial.println("WiFi connected");
  90.        Blynk.begin(auth, ssid, pass);
  91.  timer.setInterval(1000L, sendsen);
  92. }
  93.  
  94. void loop(){
  95.  
  96.  
  97.   warunek();
  98.   wyswietlacz();
  99.   sendsen();
  100.   checkUp();
  101.   checkDown();
  102.  
  103.  
  104.  
  105.    Blynk.run();
  106.   timer.run();
  107.   float temp = sensors.getTempCByIndex(0);
  108.                     if(timeStart2 - previousMillis2 >= t){
  109.                       previousMillis2 = timeStart2;
  110.                          if (client.connect(server,80))   //   "184.106.153.149" or api.thingspeak.com
  111.                       {  
  112.                            
  113.                              String postStr = apiKey;
  114.                              postStr +="&field1=";
  115.                              postStr += String(temp);
  116.                              postStr +="&field2=";
  117.                              postStr += String(x);
  118.                              postStr +="&field3=";
  119.                              postStr += String(CalcSt);  
  120.                                    
  121.                              postStr += "\r\n\r\n";
  122.  
  123.                              client.print("POST /update HTTP/1.1\n");
  124.                              client.print("Host: api.thingspeak.com\n");
  125.                              client.print("Connection: close\n");
  126.                              client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
  127.                              client.print("Content-Type: application/x-www-form-urlencoded\n");
  128.                              client.print("Content-Length: ");
  129.                              client.print(postStr.length());
  130.                              client.print("\n\n");
  131.                              client.print(postStr);
  132.  
  133.                        
  134.                              Serial.println("%. Send to Thingspeak.");
  135.                         }
  136.           client.stop();
  137.  
  138.           Serial.println("Waiting...");
  139.  
  140.   // thingspeak needs minimum 15 sec delay between updates
  141.                     }
  142. }
  143.     void sendsen(){
  144.      sensors.requestTemperatures();
  145.      float temp = sensors.getTempCByIndex(0);
  146.       Blynk.virtualWrite(V5, temp); //sending to Blynk
  147.       Blynk.virtualWrite(V6, x);
  148.       Blynk.virtualWrite(V4, CalcSt);
  149.     }
  150.  
  151.     BLYNK_WRITE(V1){
  152.        CalcSt = param.asInt();
  153.      
  154.  
  155.     }  
  156.  
  157.  
  158. void checkUp(){ // przycisk zliczajacy w gore
  159.   upbutt = digitalRead(Up); //przepisanie do zmiennej przycisku
  160.    if(upbutt !=uplastbutt){ // jeśli stan się zmienił, zwiększ licznik
  161.     if(upbutt == LOW){
  162.       bPress = true;
  163.       CalcSt ++; //dodanie liczby
  164.     }
  165.     delay(20);
  166.   }
  167.   uplastbutt = upbutt; // zapisanie ostatniego stanu
  168. }
  169.  
  170. void checkDown(){ // przycisk zliczajacy w dol
  171.   downbutt = digitalRead(Down); //przepisanie do zmiennej przycisku
  172.  if(downbutt != downlastbutt){
  173.     if(downbutt == LOW){
  174.       bPress=true;
  175.       CalcSt --;
  176.     }
  177.     delay(20);
  178.   }
  179.   downlastbutt = downbutt; // zapisanie ostatniego stanu
  180. }
  181. /*
  182.  void wyswietlacz(){
  183. float temp = sensors.getTempCByIndex(0);
  184.   lcd.setCursor(0,1);
  185.   lcd.print("T:");
  186.   lcd.print(sensors.getTempCByIndex(0)  );
  187.   Serial.println(temp);  
  188.    lcd.setCursor(0,0);
  189.    lcd.print("Ustaw temp: ");
  190.    lcd.print(CalcSt);
  191.    }
  192.  
  193.  
  194.  
  195.  
  196. void warunek() { //włącza bądź wyłącza 230v
  197.    sensors.requestTemperatures();
  198.    float temp = sensors.getTempCByIndex(0);
  199.  
  200.   if(temp < CalcSt){ // jeśli temp jest mniejsza od ustaw temp
  201.    digitalWrite(przekaznik, HIGH); // to ma włączyć
  202.  
  203.   }else if(temp > CalcSt+5){ // jeśli temp jest większa niż ustaw temp +5
  204.     digitalWrite(przekaznik, LOW); // to ma wyłączyć
  205.   }
  206.  
  207.   while(isCounting && millis() - timeStart >= (21600*1000)){ // wyłącznik czasowy
  208.     isCounting = false;
  209.     for(;;){
  210.    digitalWrite(przekaznik, LOW);
  211.     }
  212.     Serial.println("Off");
  213.   }
  214.  
  215.       for(int i = 0; i<(temp>CalcSt);i++){
  216.   if(isCounting &&((millis()-timeStart)>=(i*1000))){
  217.     isCounting = false;
  218.      x = (millis()/6000);
  219.  
  220.      lcd.setCursor(11,1);
  221.      lcd.print(x);
  222.    
  223.     }
  224.   }
  225.   */
  226.  
  227.  
  228. }

Replies to Untitled rss

Title Name Language When
Re: Untitled Mungo Moth text 4 Years ago.