Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LCD pins
- // RST -> 6
- // CE -> 7
- // DC -> 5
- // Din -> 4
- // Clk -> 3
- // VCC & Bl -> 3.3V
- // DHTPIN 12
- // Dallas pin 2
- // ESP8266
- // VCC & CH_PH -> 3.3V
- // GND -> GND
- // TX -> 0 (RX)
- // RX -> 1 (TX)
- // BMP180
- // GND -> GND
- // VIN -> 3.3V
- // SDA -> A4
- // SCL -> A5
- // Подключаем датчик температуры и влажности DHT11
- #include "DHT.h"
- #define DHTPIN 12 // указываем пин подключения DHT11
- #define DHTTYPE DHT11
- // Подключаем датчик атмосферного давления BMP180
- #include <Wire.h>
- #include <Adafruit_BMP085.h>
- // Подключаем температурный датчик DS18B20
- #include <OneWire.h>
- #include <DallasTemperature.h>
- // Указываем пин подключения DS18B20
- #define ONE_WIRE_BUS 2
- // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
- OneWire oneWire(ONE_WIRE_BUS);
- // Pass our oneWire reference to Dallas Temperature.
- DallasTemperature sensors(&oneWire);
- // arrays to hold device address
- DeviceAddress insideThermometer;
- // Подключаем LCD Nokia 5110
- #include <PCD8544.h>
- static PCD8544 lcd;
- // Wi-Fi ini start
- #define SSID "Al_HOME"
- #define PASSWORD "08112004"
- //#define server "93.81.252.64" //test.alninyo.ru
- #define server "195.208.1.147" //test.sc13.ru
- #include "uartWIFI.h"
- #include <SoftwareSerial.h>
- WIFI wifi;
- // Wi-Fi ini end
- Adafruit_BMP085 bmp;
- DHT dht(DHTPIN, DHTTYPE);
- int tempDS = 0; // температура от DS18B20
- int lastTempDS = 0;
- int tempBMP = 0;// температура от BMP180
- int lastTempBMP = 0;
- int pressure = 0; // атмосферное давление
- int lastPressure = 0;
- int h = 0; // влажность
- int lastH = 0;
- int t = 0; // температура от DHT11
- int lastT = 0;
- int i = 0; // счётчик 1
- unsigned long count = 0; // счётчик 2
- const unsigned long checkTime = 10000; // интервал опроса датчиков
- unsigned long lastCheckTime = 0; // переменная для хранения
- // времени последнего опроса датчиков
- unsigned long lastConnectionTime = 0;
- const unsigned long postingInterval = 60000;
- void MainLoop() {
- sensors.requestTemperatures();
- tempDS = sensors.getTempC(insideThermometer);
- tempBMP = bmp.readTemperature();
- pressure = bmp.readPressure()/133.3;
- h = dht.readHumidity();
- t = dht.readTemperature();
- if ((lastTempDS != tempDS) ||
- (lastT != t) ||
- (lastTempBMP != tempBMP) ||
- (lastPressure != pressure) ||
- (lastH != h)){
- lastTempDS = tempDS;
- lastT = t;
- lastTempBMP = tempBMP;
- lastH = h;
- lastPressure = pressure;
- Serial.print(lastTempDS);
- Serial.print(", ");
- Serial.print(lastT);
- Serial.print(", ");
- Serial.print(lastTempBMP);
- Serial.print(", ");
- Serial.print(lastH);
- Serial.print(", ");
- Serial.print(lastPressure);
- Serial.print(", ");
- Serial.println(millis());
- }
- lcd.setCursor(0,0);
- lcd.print("Темп. DS/DH/BM");
- lcd.setCursor(0,1);
- lcd.print(lastTempDS);
- lcd.print("/");
- lcd.print(lastT);
- lcd.print("/");
- lcd.print(lastTempBMP);
- lcd.setCursor(0,2);
- lcd.print("Влажность ");
- lcd.print(lastH);
- lcd.print(" %");
- lcd.setCursor(0,3);
- lcd.print("Давление ");
- lcd.setCursor(0,4);
- lcd.print(lastPressure);
- lcd.print(" мм рт.ст.");
- }
- void setup() {
- Serial.begin(9600);
- lcd.begin(84, 48);
- lcd.setCursor(0,0);
- lcd.print("Включаю BMP180");
- if (!bmp.begin()) {
- Serial.println("Could not find a valid BMP085 sensor, check wiring!");
- lcd.setCursor(0,0);
- lcd.print("Проблема с BMP180!");
- while (1) {}
- }
- delay(1000);
- lcd.setCursor(0,0);
- lcd.print("Включаю DS18b20");
- delay(1000);
- sensors.begin();
- lcd.setCursor(0,0);
- lcd.print("Включаю DHT11");
- delay(1000);
- dht.begin();
- if (!sensors.getAddress(insideThermometer, 0)) {
- Serial.println("Unable to find address for Device 0");
- lcd.setCursor(0,1);
- lcd.print("Проблема с DS18B20!");
- }
- // set the resolution to 9 bit
- sensors.setResolution(insideThermometer, 9);
- lcd.setCursor(0,0);
- lcd.print(" Погода в доме");
- lcd.setCursor(0,2);
- lcd.print(" Версия 3 ");
- lcd.setCursor(0,4);
- lcd.print(" Загрузка ");
- wifi.begin();
- bool b = wifi.Initialize(STA, SSID, PASSWORD);
- if(!b)
- {
- Serial.println("Init error");
- }
- delay(8000);
- String ipstring = wifi.showIP();
- Serial.println(ipstring);
- }
- void loop() {
- if (lastCheckTime == 0 && count == 0) {
- MainLoop();
- }
- if ((millis()-lastCheckTime)>checkTime){
- lastCheckTime = millis();
- if (i == 6){
- lcd.clear();
- i = 0;
- }
- MainLoop();
- i++;
- }
- // Wi-Fi start
- char message[320];
- // if you're not connected, and ten seconds have passed since
- // your last connection, then connect again and send data:
- if((millis() - lastConnectionTime > postingInterval) && (lastTempDS != tempDS || lastT != t
- || lastTempBMP != tempBMP || lastH != h || lastPressure != pressure)) {
- // String getRequest = "GET http://test.alninyo.ru/test.php?tIn=";
- String getRequest = "GET http://test.sc13.ru/test.php?tIn=";
- getRequest+= lastTempDS;
- getRequest+= "&tOut=";
- getRequest+= lastTempBMP;
- getRequest+= "&h=";
- getRequest+= lastH;
- getRequest+= "&t=";
- getRequest+= lastT;
- getRequest+= "&pres=";
- getRequest+= lastPressure;
- getRequest+= "&c=08112004";
- getRequest+= " HTTP/1.0\r\n\r\n";
- // if there's a successful connection:
- if (wifi.ipConfig(TCP,server, 80)) {
- Serial.println("connecting...");
- // send the HTTP PUT request:
- //wifi.Send("GET / HTTP/1.0\r\n\r\n");
- wifi.Send(getRequest);
- // Serial.println(getRequest);
- // note the time that the connection was made:
- lastConnectionTime = millis();
- Serial.print("lastConnectionTime = ");
- Serial.println(lastConnectionTime);
- }
- else {
- // if you couldn't make a connection:
- Serial.println("connection failed");
- Serial.println("disconnecting.");
- wifi.closeMux();
- }
- }
- // if there's incoming data from the net connection.
- // send it out the serial port. This is for debugging
- // purposes only:
- if(wifi.ReceiveMessage(message))
- {
- Serial.println(message);
- wifi.closeMux();
- count++;
- lcd.setCursor(0,5);
- lcd.print("Ушло ");
- lcd.print(count);
- lcd.print(" раз");
- }
- // Wi-Fi end
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement