Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Program odczytuje temperaturę kilku czujników
  2.  
  3. #include <OneWire.h>
  4. #include <DallasTemperature.h>
  5.  
  6. // Numer pinu do którego podłaczasz czujnik
  7. #define ONEWIRE_PIN 2
  8.  
  9. // Ilość czujników
  10. #define SENSORS_NUM 3
  11.  
  12. // Adresy czujników
  13.  
  14.   DeviceAddress sensor1 = { 0x28, 0x58, 0x28, 0x26, 0x0, 0x0, 0x80, 0xA2};
  15.   DeviceAddress sensor2 = { 0x28, 0x32, 0x41, 0x26, 0x0, 0x0, 0x80, 0x4C};
  16.   DeviceAddress sensor3 = { 0x28, 0xFF, 0x76, 0x28, 0x34,0x16, 0x3, 0x31};
  17.      
  18.  
  19.  
  20. OneWire onewire(ONEWIRE_PIN);
  21. DallasTemperature sensors(&onewire);
  22.  
  23.  
  24. void setup() {
  25.   Serial.begin(9600);
  26.   while(!Serial);
  27.   Serial1.begin(115200);
  28.  
  29.   while(!wyslij("AT","OK",100))
  30.   {
  31.     Serial.println("Bład komunikacji z modulem");
  32.     delay(1000);
  33.   }
  34.  
  35.   Serial.println("Rozpoczeto komunikacje");
  36.  
  37.   if(wyslij("AT+CWMODE=1","OK", 200))
  38.   Serial.println("CWMODE - OK---> TRYB PRACY JAKO KLIENT");
  39.   if(wyslij("AT+CIPMODE=0","OK", 200))
  40.   Serial.println("CIPMODE - OK---> TRYB PRACY 0");
  41.   if(wyslij("AT+CIPMUX=1","OK", 200));
  42.   Serial.println("CIPMUX - OK---> OBSLUGA WIELU POLACZEN NA RAZ");
  43.  
  44.   if(wyslij("AT+CWJAP=\"FunBox2-9D15\",\"JB,mpJB,mp\"","OK",5000))
  45.   Serial.println("Polaczono z funboxem");
  46.  
  47.   //Serial1.println("AT+CIFSR");
  48.   Serial.println(Serial1.readString());
  49.  
  50.   if(wyslij("AT+CIPSERVER=1,80","OK",2000))
  51.   Serial.println("Uruchomiono serwer na adresie ");
  52.  
  53.   Serial1.println("AT+CIFSR");
  54.   Serial.println(Serial1.readString());
  55.  
  56.   sensors.begin();
  57.  
  58. }
  59.  
  60. char klient[1];
  61. char bufor [50];
  62. String strona;
  63. void loop() {
  64.   while(Serial1.available() >0 )
  65.   {
  66.     if(Serial1.find("+IPD,"))
  67.     {
  68.       Serial1.readBytesUntil(',',klient,1);
  69.       Serial.println();
  70.  
  71.       Serial.println("Zapytanie ID: ");
  72.       Serial.println(klient[0]);
  73.  
  74.      // AT+CIPSEND=1,50
  75.      sensors.requestTemperatures();
  76.     Serial.print("Sensor 1(*C): ");
  77.     Serial.print(sensors.getTempC(sensor1));
  78.  
  79.       strona = "<html><head><title>Pomiar temperatury</title></head><body><h2>Temperatura 1: "+ String(sensors.getTempC(sensor1)) + "*C</h2><p><h2>Temperatura 2: "+ String(sensors.getTempC(sensor2)) + "*C</h2></p><p><h2>Temperatura 3: "+ String(sensors.getTempC(sensor3)) + "*C</h2></p></body></html>";
  80.      
  81.       sprintf(bufor, "AT+CIPSEND=%c,%d",klient[0],strona.length());
  82.       if(wyslij(bufor,">",100))
  83.       Serial.println("Zadanie wyslania...");
  84.       if(wyslij(strona, "OK",100))
  85.       Serial.println("Wyslano dane");
  86.       sprintf(bufor, "AT+CIPCLOSE=%c",klient[0]);
  87.       if(wyslij(bufor,"OK",100));
  88.       Serial.println("Zamknieto polaczenie");
  89.            
  90.     }
  91.   }
  92. }
  93.  
  94. boolean wyslij(String Komenda_AT, char *Odpowiedz_AT, int czas_czekania)
  95. {
  96.   Serial1.println(Komenda_AT);
  97.   delay(czas_czekania);
  98.   while(Serial1.available() > 0)
  99.   {
  100.     if(Serial1.find(Odpowiedz_AT))
  101.     return 1;
  102.   }
  103.  
  104.  return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement