Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Program odczytuje temperaturę kilku czujników
- #include <OneWire.h>
- #include <DallasTemperature.h>
- // Numer pinu do którego podłaczasz czujnik
- #define ONEWIRE_PIN 2
- // Ilość czujników
- #define SENSORS_NUM 3
- // Adresy czujników
- DeviceAddress sensor1 = { 0x28, 0x58, 0x28, 0x26, 0x0, 0x0, 0x80, 0xA2};
- DeviceAddress sensor2 = { 0x28, 0x32, 0x41, 0x26, 0x0, 0x0, 0x80, 0x4C};
- DeviceAddress sensor3 = { 0x28, 0xFF, 0x76, 0x28, 0x34,0x16, 0x3, 0x31};
- OneWire onewire(ONEWIRE_PIN);
- DallasTemperature sensors(&onewire);
- void setup() {
- Serial.begin(9600);
- while(!Serial);
- Serial1.begin(115200);
- while(!wyslij("AT","OK",100))
- {
- Serial.println("Bład komunikacji z modulem");
- delay(1000);
- }
- Serial.println("Rozpoczeto komunikacje");
- if(wyslij("AT+CWMODE=1","OK", 200))
- Serial.println("CWMODE - OK---> TRYB PRACY JAKO KLIENT");
- if(wyslij("AT+CIPMODE=0","OK", 200))
- Serial.println("CIPMODE - OK---> TRYB PRACY 0");
- if(wyslij("AT+CIPMUX=1","OK", 200));
- Serial.println("CIPMUX - OK---> OBSLUGA WIELU POLACZEN NA RAZ");
- if(wyslij("AT+CWJAP=\"FunBox2-9D15\",\"JB,mpJB,mp\"","OK",5000))
- Serial.println("Polaczono z funboxem");
- //Serial1.println("AT+CIFSR");
- Serial.println(Serial1.readString());
- if(wyslij("AT+CIPSERVER=1,80","OK",2000))
- Serial.println("Uruchomiono serwer na adresie ");
- Serial1.println("AT+CIFSR");
- Serial.println(Serial1.readString());
- sensors.begin();
- }
- char klient[1];
- char bufor [50];
- String strona;
- void loop() {
- while(Serial1.available() >0 )
- {
- if(Serial1.find("+IPD,"))
- {
- Serial1.readBytesUntil(',',klient,1);
- Serial.println();
- Serial.println("Zapytanie ID: ");
- Serial.println(klient[0]);
- // AT+CIPSEND=1,50
- sensors.requestTemperatures();
- Serial.print("Sensor 1(*C): ");
- Serial.print(sensors.getTempC(sensor1));
- 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>";
- sprintf(bufor, "AT+CIPSEND=%c,%d",klient[0],strona.length());
- if(wyslij(bufor,">",100))
- Serial.println("Zadanie wyslania...");
- if(wyslij(strona, "OK",100))
- Serial.println("Wyslano dane");
- sprintf(bufor, "AT+CIPCLOSE=%c",klient[0]);
- if(wyslij(bufor,"OK",100));
- Serial.println("Zamknieto polaczenie");
- }
- }
- }
- boolean wyslij(String Komenda_AT, char *Odpowiedz_AT, int czas_czekania)
- {
- Serial1.println(Komenda_AT);
- delay(czas_czekania);
- while(Serial1.available() > 0)
- {
- if(Serial1.find(Odpowiedz_AT))
- return 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement