Proszę z GUI po 192.162.4.1 -zamień tylko w libraries w Arduino nowe SuplaDevice i dorzuć SuplaGUI z tąd: (pierwszy post )- viewtopic.php?f=6&t=4957qba93 wrote: Sat Jul 06, 2019 8:09 pmTak jak na PW CI napisałem popełniłem błąd wstawiając nie ten kod ten jest od czegoś innego, żly kod dałem tu jest poprawny z czujnikiem cisnieniapiomar2 wrote: Sat Jul 06, 2019 8:04 pm Ja nie bardzo teraz rozumiem. Kod był do czujnika odległości i chodziło o dodanie DS18B20 . To skąd teraz BME280?Code: Select all
Hej jestem głupszy od dziurawego sandała nie ten kod na forum wkleiłem.Chciałem dodać do tego /** Supla.org NodeMCU WiFi minimal example Author: Programistyk - Kamil Kaminski <[email protected]> This example shows how to configure SuplaDevice for building for NodeMCU within Arduino IDE */ #define LIGHTSENSORPIN A0 //Ambient light sensor reading #include <BH1750FVI.h> #include <srpc.h> #include <log.h> #include <eh.h> #include <proto.h> #include <IEEE754tools.h> // We define our own ethernet layer #define SUPLADEVICE_CPP #include <SuplaDevice.h> #include <lck.h> #include <WiFiClient.h> #include <ESP8266WiFiType.h> #include <ESP8266WiFi.h> #include <ESP8266WiFiScan.h> #include <ESP8266WiFiMulti.h> #include <WiFiServer.h> #include <ESP8266WiFiGeneric.h> #include <WiFiClientSecure.h> #include <ESP8266WiFiAP.h> #include <ESP8266WiFiSTA.h> #include <WiFiUdp.h> #include <Wire.h> #include <OneWire.h> #include <DallasTemperature.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #include <Adafruit_Sensor.h> #include <Adafruit_BME280.h> #define OLED_RESET 0 Adafruit_SSD1306 display(OLED_RESET); // GPIO5 - SCL , GPIO4 -SDA String light; #define SEALEVELPRESSURE_HPA (1023.0) Adafruit_BME280 bme; // I2C #define NUMFLAKES 10 #define XPOS 0 #define YPOS 1 #define DELTAY 2 BH1750FVI LightSensor(BH1750FVI::k_DevModeContLowRes); #define LOGO32_GLCD_HEIGHT 32 #define LOGO32_GLCD_WIDTH 32 static const unsigned char PROGMEM temp_glcd_bmp[] = { // temp_home 0x00, 0x03, 0xc0, 0x00, 0x00, 0x04, 0x20, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x50, 0x00, 0x00, 0x08, 0x50, 0x00, 0x00, 0x08, 0x50, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x09, 0x50, 0x00, 0x00, 0x08, 0xd0, 0x00, 0x00, 0x0b, 0x10, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x17, 0xe8, 0x00, 0x00, 0x2f, 0xf4, 0x00, 0x00, 0x2f, 0x94, 0x00, 0x00, 0x2f, 0xb4, 0x00, 0x00, 0x2f, 0xf4, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x13, 0xc8, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x03, 0xc0, 0x00 }; static const unsigned char PROGMEM pressure_glcd_bmp[] = { // 'pressure' 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x01, 0xc1, 0xc1, 0xf8, 0x03, 0xc3, 0xc1, 0xf8, 0x03, 0x83, 0x81, 0xf8, 0x03, 0x03, 0x00, 0x18, 0x07, 0x07, 0x00, 0x18, 0x07, 0x07, 0x00, 0xf8, 0x07, 0x07, 0x00, 0xf8, 0x07, 0x07, 0x00, 0xf8, 0x07, 0x07, 0x00, 0x18, 0x03, 0x03, 0x00, 0x18, 0x03, 0x83, 0x80, 0x18, 0x03, 0x83, 0x81, 0xf8, 0x03, 0x83, 0x81, 0xf8, 0x03, 0x83, 0x80, 0x18, 0x01, 0x81, 0x80, 0x18, 0x01, 0x81, 0x80, 0x18, 0x03, 0x83, 0x80, 0xf8, 0x03, 0x83, 0x80, 0xf8, 0x03, 0x83, 0x80, 0xf8, 0x13, 0x93, 0x80, 0x18, 0x1f, 0x1f, 0x00, 0x18, 0x1f, 0x1f, 0x01, 0xf8, 0x1e, 0x1e, 0x01, 0xf8, 0x1f, 0x1f, 0x01, 0xf8, 0x1f, 0x9f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const unsigned char PROGMEM humidity_glcd_bmp[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x01, 0xce, 0x00, 0x00, 0x03, 0xcf, 0x00, 0x00, 0x03, 0x87, 0x00, 0x00, 0x07, 0x87, 0x80, 0x00, 0x07, 0x03, 0x80, 0x00, 0x0e, 0x01, 0xc0, 0x00, 0x1e, 0x01, 0xe0, 0x00, 0x1c, 0x00, 0xe0, 0x00, 0x38, 0x00, 0x70, 0x00, 0x78, 0x00, 0x78, 0x00, 0x70, 0x80, 0x38, 0x00, 0x61, 0x48, 0x18, 0x00, 0xe2, 0x48, 0x1c, 0x00, 0xe3, 0x50, 0x1c, 0x00, 0xe1, 0xa0, 0x1c, 0x00, 0xe0, 0x2a, 0x1c, 0x00, 0xe0, 0x52, 0x1c, 0x00, 0xe0, 0x92, 0x1c, 0x00, 0x60, 0x8c, 0x18, 0x00, 0x70, 0x00, 0x38, 0x00, 0x38, 0x00, 0x70, 0x00, 0x3c, 0x00, 0xf0, 0x00, 0x1e, 0x01, 0xe0, 0x00, 0x0f, 0xff, 0xc0, 0x00, 0x07, 0xff, 0x80, 0x00, 0x00, 0xfc, 0x00, 0x00 }; static const unsigned char PROGMEM rain_glcd_bmp[] = { 0x00, 0x00, 0x00, 0x00, // ················ 0x00, 0x00, 0x00, 0x00, // ················ 0x00, 0x00, 0x00, 0x00, // ················ 0x00, 0x00, 0x00, 0x00, // ················ 0x00, 0x00, 0x00, 0x00, // ················ 0x00, 0x00, 0x00, 0x00, // ················ 0x00, 0x00, 0x00, 0x00, // ················ 0x00, 0x00, 0x00, 0x00, // ················ 0x00, 0x00, 0x00, 0x00, // ················ 0x00, 0x00, 0x00, 0x00, // ················ 0x00, 0xF3, 0xE0, 0x00, // ····██·██▌······ 0x01, 0x8E, 0x18, 0x00, // ···▐▌·█▌·▐▌····· 0x03, 0x0C, 0x08, 0x00, // ···█··█···▌····· 0x04, 0x38, 0x0F, 0x00, // ··▐··█▌···██···· 0x08, 0x28, 0x11, 0x80, // ··▌··▌▌··▐·▐▌··· 0x10, 0x40, 0x00, 0xC0, // ·▐··▐·······█··· 0x10, 0x80, 0x00, 0x40, // ·▐··▌·······▐··· 0x0F, 0x00, 0x00, 0x40, // ··██········▐··· 0x01, 0x00, 0x00, 0x40, // ···▐········▐··· 0x01, 0x00, 0x00, 0x80, // ···▐········▌··· 0x00, 0xFF, 0xFF, 0x00, // ····████████···· 0x00, 0x14, 0x96, 0x00, // ·····▐▐·▌▐▐▌···· 0x00, 0x24, 0xA4, 0x00, // ·····▌▐·▌▌▐····· 0x00, 0x21, 0x0C, 0x00, // ·····▌·▐··█····· 0x00, 0x40, 0x08, 0x00, // ····▐·····▌····· 0x00, 0x10, 0x80, 0x00, // ·····▐··▌······· 0x00, 0x10, 0x80, 0x00, // ·····▐··▌······· 0x00, 0x00, 0x00, 0x00, // ················ 0x00, 0x00, 0x00, 0x00, // ················ 0x00, 0x00, 0x00, 0x00, // ················ 0x00, 0x00, 0x00, 0x00, // ················ 0x00, 0x00, 0x00, 0x00 // ················ }; static const unsigned char PROGMEM lux_glcd_bmp[] = { 0x00, 0x01, 0xC0, 0x00, // ·······▐█······· 0x00, 0x01, 0xC0, 0x00, // ·······▐█······· 0x00, 0xC1, 0xC1, 0x80, // ····█··▐█··▐▌··· 0x00, 0xE1, 0xC3, 0x80, // ····█▌·▐█··█▌··· 0x00, 0x71, 0xC7, 0x00, // ····▐█·▐█·▐█···· 0x00, 0x70, 0x87, 0x00, // ····▐█··▌·▐█···· 0x00, 0x30, 0x06, 0x00, // ·····█····▐▌···· 0x18, 0x07, 0xF0, 0x0C, // ·▐▌···▐███····█· 0x3E, 0x1F, 0xF8, 0x3C, // ·██▌·▐████▌··██· 0x1F, 0x3F, 0x7E, 0x78, // ·▐██·███▐██▌▐█▌· 0x07, 0x78, 0x0E, 0x70, // ··▐█▐█▌···█▌▐█·· 0x00, 0x70, 0x07, 0x00, // ····▐█····▐█···· 0x00, 0xE0, 0x03, 0x80, // ····█▌·····█▌··· 0x00, 0xE0, 0x03, 0x80, // ····█▌·····█▌··· 0x7C, 0xC0, 0x03, 0x9F, // ▐██·█······█▌▐██ 0xFE, 0xC0, 0x01, 0xBF, // ███▌█······▐▌███ 0x7C, 0xC0, 0x01, 0x9F, // ▐██·█······▐▌▐██ 0x00, 0xE0, 0x03, 0x80, // ····█▌·····█▌··· 0x00, 0xE0, 0x03, 0x80, // ····█▌·····█▌··· 0x00, 0x70, 0x07, 0x00, // ····▐█····▐█···· 0x07, 0x78, 0x0F, 0x70, // ··▐█▐█▌···██▐█·· 0x0F, 0x3E, 0x3E, 0x78, // ··██·██▌·██▌▐█▌· 0x1E, 0x1F, 0xFC, 0x3C, // ·▐█▌·▐█████··██· 0x18, 0x07, 0xF0, 0x0C, // ·▐▌···▐███····█· 0x00, 0x30, 0x06, 0x00, // ·····█····▐▌···· 0x00, 0x70, 0x87, 0x00, // ····▐█··▌·▐█···· 0x00, 0x71, 0xC7, 0x00, // ····▐█·▐█·▐█···· 0x00, 0xE1, 0xC3, 0x80, // ····█▌·▐█··█▌··· 0x00, 0xC1, 0xC3, 0x80, // ····█··▐█··█▌··· 0x00, 0x01, 0xC1, 0x00, // ·······▐█··▐···· 0x00, 0x01, 0xC0, 0x00, // ·······▐█······· 0x00, 0x00, 0x80, 0x00 // ········▌······· }; static const unsigned char PROGMEM logo32_glcd_bmp[] = { // 'logo SUPLA' 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00, 0x0e, 0x0e, 0x00, 0x00, 0x0c, 0x06, 0x00, 0x00, 0x1c, 0x03, 0x00, 0x00, 0x1c, 0x03, 0x00, 0x00, 0x1c, 0x03, 0x00, 0x00, 0x0c, 0x07, 0x00, 0x00, 0x0e, 0x0f, 0x80, 0x00, 0x07, 0xfc, 0xe0, 0x00, 0x03, 0xf8, 0x30, 0x00, 0x00, 0xf0, 0x0d, 0xe0, 0x00, 0x10, 0x07, 0x30, 0x00, 0x18, 0x02, 0x10, 0x00, 0x18, 0x06, 0x18, 0x00, 0x08, 0x02, 0x10, 0x00, 0x08, 0x03, 0xf0, 0x00, 0x0c, 0x07, 0xc0, 0x00, 0x04, 0x0c, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x04, 0x10, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; static const unsigned char PROGMEM ASL_glcd_bmp[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x08, 0x21, 0x00, 0x00, 0x0c, 0x03, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x3f, 0x0c, 0x00, 0x00, 0x61, 0x84, 0x00, 0x00, 0xc0, 0xc4, 0xe0, 0x01, 0xc0, 0xf4, 0x00, 0x03, 0x00, 0x1c, 0x00, 0x06, 0x00, 0x0c, 0x00, 0x06, 0x00, 0x0c, 0x00, 0x06, 0x10, 0xcd, 0x00, 0x03, 0x10, 0x99, 0x00, 0x01, 0x84, 0x30, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; char* Message[] = {"This is string 1", "Already initialized", "Cb not assigned", "Invalid GUID", "Unknown server address", "Unknow location ID", "Initialized", "Channel limit exceeded", "Rozlaczony", "Rejstracja w toku", "Iterate fail", "Protocol version error", "Bad credentials", "Temporarily unawaliable", "Location conflict", "Channel conflict", "Polaczony i gotowy", "Device is diasbled", "Location is disabled", "Device limit execeeded" }; #if (SSD1306_LCDHEIGHT != 64) //#error("Height incorrect, please fix Adafruit_SSD1306.h!"); #endif // ***** logowanie WiFi ******************************************************************************** WiFiClient client; // Setup Supla connection const char* ssid = "vodafone-DC3C"; // zamiast tych xxx wpisz nazwę sieci WIFI const char* password = "xxx"; // hasło do sieci wifi char str[10]; char StatCommStr[25]; int StatCommInt; byte Icon; byte FiveSek; //// ******* BME280 Temperatura i wilgotnosc ********************************* void get_temperature_and_humidity (int channelNumber, double *temp, double *humidity) { *temp = bme.readTemperature(); Serial.print("Temperature = "); Serial.print(bme.readTemperature()); Serial.println(" *C"); *humidity = bme.readHumidity(); Serial.print("Humidity = "); Serial.print(bme.readHumidity()); // wyremowane dla BMP280 Serial.println(" %"); if ( isnan(*temp) || isnan(*humidity) ) { *temp = -275; *humidity = -1; } } ///***********DESZCZ******************************************************* double get_rain(int channelNumber, double rain) { rain = 10; Serial.print("Rain = "); Serial.print(rain); Serial.println(" mm"); return rain; } //// ******* Ciśnienie BME 280 ***************************************************** double get_pressure(int channelNumber, double pressure) { pressure = bme.readPressure() / 100.0F; Serial.print("Pressure = "); Serial.print(bme.readPressure() / 100); Serial.println(" hPa"); return pressure; } ////******* Natężenie światła zrobione obsługą czujnika odległości double get_distance(int channelNumber, double t) { // float lux = analogRead(LIGHTSENSORPIN); //TEMT6000 double lux = LightSensor.GetLightIntensity(); //BH1750 t = abs(lux); Serial.print("Natezenie swiatla = "); Serial.print(LightSensor.GetLightIntensity()); delay(1250); return t; } void timer0_ISR (void) { FiveSek++; if (FiveSek == 5) { FiveSek = 0; Icon++; if (Icon == 6) Icon = 1; } timer0_write(ESP.getCycleCount() + 80000000L); // 80MHz == 1sec } //// ******* Funkcja główna ********************************************************************************* void setup() { Serial.begin(9600); //BH1750 //pinMode(LIGHTSENSORPIN, INPUT); // dodany czujnik natężenia LightSensor.begin(); noInterrupts(); timer0_isr_init(); timer0_attachInterrupt(timer0_ISR); timer0_write(ESP.getCycleCount() + 80000000L); // 80MHz == 1sec interrupts(); if (!bme.begin(0x76)) { Serial.println("Could not find a valid BME280 sensor, check wiring!"); while (1); } display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x64) Icon = 0; // Clear the buffer. display.clearDisplay(); // text display tests display.setTextSize(3); display.setTextColor(WHITE); display.setRotation(2); display.setCursor(30, 25); display.print("SUPLA"); drawbitmap(logo32_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH); display.display(); // Replace the falowing GUID char GUID[SUPLA_GUID_SIZE] = {0x8B, 0x4A, 0x5B, 0xB5, 0x6B, 0x68, 0x76, 0x5B, 0xF5, 0xEA, 0x9A, 0x8C, 0x73, 0xC6, 0x38, 0x1D}; // GUID that you can retrieve from https://www.supla.org/arduino/get-guid // Ethernet MAC address uint8_t mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; /* Having your device already registered at cloud.supla.org, you want to change CHANNEL sequence or remove any of them, then you must also remove the device itself from cloud.supla.org. Otherwise you will get "Channel conflict!" error. */ // CHANNEL0 SuplaDevice.addRainSensor(); //deszczu czujnik SuplaDevice.addDHT22(); // ten objekt jest tylko po to aby w aplikacji wyĹ›wietlic temp i wilgotnosc SuplaDevice.addDistanceSensor(); // ten obiekt wyswietla natezenie niestety bez jednostek (LUX) SuplaDevice.addPressureSensor(); // cisnienie SuplaDevice.setName("czujka"); SuplaDevice.setStatusFuncImpl(&status_func); SuplaDevice.begin(GUID, // Global Unique Identifier mac, // Ethernet MAC address "sss", // SUPLA server address sss4, // Location ID "sss"); // Location Password } // *********************************************************************************************************** void loop() { SuplaDevice.iterate(); DisplayTemp(); } // **** Obsługa OLED **************************************************************************************************** void DisplayTemp() { double Light_Intensity = LightSensor.GetLightIntensity(); int rain = 0.01; display.clearDisplay(); display.setTextSize(3); display.setTextColor(WHITE); display.setRotation(2); display.setCursor(45, 25); switch (Icon) { case 1: display.setTextSize(3); display.setCursor(45, 25); display.print(bme.readTemperature(), 0); display.print((char)247); display.println("C"); drawbitmap(temp_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH); break; case 2: display.setTextSize(3); display.setCursor(45, 25); display.print(bme.readHumidity(), 0); display.println("%"); drawbitmap(humidity_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH); break; case 3: display.setTextSize(2); display.setCursor(32, 25); display.print(bme.readPressure() / 100.0F, 0); display.println(" hPa"); drawbitmap(pressure_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH); break; case 4: display.setTextSize(2); display.setCursor(45, 25); display.print(Light_Intensity, 0); display.println(" Lux"); drawbitmap(lux_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH); break; case 5: display.setTextSize(2); display.setCursor(19, 29); // display.print(rain, 0); display.println("0,01 l/m2"); drawbitmap(rain_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH); break; /* case 5: display.setTextSize(2); display.setCursor(45, 25); display.print(bme.readAltitude(SEALEVELPRESSURE_HPA), 0); display.println(" npm"); drawbitmap(ASL_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH); break;*/ //--------------------- }; display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0, 55); display.print(Message[StatCommInt - 1]); display.display(); display.display(); }; //DisplayTemp void drawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) { uint8_t icons[NUMFLAKES][3]; display.drawBitmap(0, 0, bitmap, w, h, WHITE); } //drawbitmap // Supla.org ethernet layer int supla_arduino_tcp_read(void *buf, int count) { _supla_int_t size = client.available(); if ( size > 0 ) { if ( size > count ) size = count; return client.read((uint8_t *)buf, size); }; return -1; }; int supla_arduino_tcp_write(void *buf, int count) { return client.write((const uint8_t *)buf, count); }; bool supla_arduino_svr_connect(const char *server, int port) { return client.connect(server, 2015); } bool supla_arduino_svr_connected(void) { return client.connected(); } void supla_arduino_svr_disconnect(void) { client.stop(); } void supla_arduino_eth_setup(uint8_t mac[6], IPAddress *ip) { // Serial.println("WiFi init"); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } // Serial.print("\nlocalIP: "); // Serial.println(WiFi.localIP()); //Serial.print("subnetMask: "); // Serial.println(WiFi.subnetMask()); //Serial.print("gatewayIP: "); //Serial.println(WiFi.gatewayIP()); } SuplaDeviceCallbacks supla_arduino_get_callbacks(void) { SuplaDeviceCallbacks cb; cb.tcp_read = &supla_arduino_tcp_read; cb.tcp_write = &supla_arduino_tcp_write; cb.eth_setup = &supla_arduino_eth_setup; cb.svr_connected = &supla_arduino_svr_connected; cb.svr_connect = &supla_arduino_svr_connect; cb.svr_disconnect = &supla_arduino_svr_disconnect; cb.get_rain = get_rain; cb.get_temperature_and_humidity = get_temperature_and_humidity; cb.get_pressure = get_pressure; cb.get_temperature = NULL; cb.get_rgbw_value = NULL; cb.set_rgbw_value = NULL; cb.get_distance = get_distance; return cb; } void status_func(int status, const char *msg) { Serial.print("Status : "); Serial.print(status); StatCommInt = status; Serial.print(" - "); Serial.println(Message[StatCommInt - 1]); display.fillRect(0, 55, 128, 65, BLACK); display.setTextSize(1); display.setTextColor(WHITE); display.setRotation(2); display.setCursor(0, 55); display.print(Message[StatCommInt - 1]); display.display(); }
ew tu masz bin do WeMos D1 mini:
Code: Select all
/* *************************************************************************
*
* Dzieki kolegom @wojtas567 i @Duch__ powstała ta wersja.
*
*
* Wszystkie potrzebne modyfikacja znajdują się w pliku "supla_settings.h"
*
* *************************************************************************
*/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPUpdateServer.h>
#include <EEPROM.h>
#include <DoubleResetDetector.h> //Bilioteka by Stephen Denne
#define SUPLADEVICE_CPP
#include <SuplaDevice.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
Adafruit_BME280 bme; // I2C
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DHT.h>
#include <BH1750FVI.h>
BH1750FVI LightSensor(BH1750FVI::k_DevModeContLowRes);
#include "supla_settings.h"
#include "supla_eeprom.h"
#include "supla_web_server.h"
extern "C" {
#include "user_interface.h"
}
#define DRD_TIMEOUT 5// Number of seconds after reset during which a subseqent reset will be considered a double reset.
#define DRD_ADDRESS 0 // RTC Memory Address for the DoubleResetDetector to use
DoubleResetDetector drd(DRD_TIMEOUT, DRD_ADDRESS);
const char* Config_Wifi_name = CONFIG_WIFI_LOGIN;
const char* Config_Wifi_pass = CONFIG_WIFI_PASSWORD;
const char* www_username;
const char* www_password;
const char* update_path = UPDATE_PATH;
WiFiClient client;
ESP8266WebServer httpServer(80);
ESP8266HTTPUpdateServer httpUpdater;
// Setup a DHT instance
DHT dht(DHTPIN, DHTTYPE);
// Setup a DS18B20 instance
OneWire oneWire(DS18B20PIN);
DallasTemperature sensors(&oneWire);
ETSTimer led_timer;
//SUPLA ****************************************************************************************************
char Supla_server[MAX_SUPLA_SERVER];
char Location_id[MAX_SUPLA_ID];
char Location_Pass[MAX_SUPLA_PASS];
//*********************************************************************************************************
void setup() {
Serial.begin(74880);
LightSensor.begin();
EEPROM.begin(EEPROM_SIZE);
dht.begin();
sensors.begin();
client.setTimeout(500);
supla_led_set(LED_CONFIG_PIN);
if ('1' != char(EEPROM.read(EEPROM_SIZE - 1))) {
czyszczenieEEPROM();
first_start();
save_guid();
}
String www_username1 = String(read_login().c_str());
String www_password1 = String(read_login_pass().c_str());
www_password = strcpy((char*)malloc(www_password1.length() + 1), www_password1.c_str());
www_username = strcpy((char*)malloc(www_username1.length() + 1), www_username1.c_str());
if (drd.detectDoubleReset()) {
drd.stop();
gui_color = GUI_GREEN;
Tryb_konfiguracji();
}
else gui_color = GUI_BLUE;
delay(5000);
drd.stop();
//SuplaDevice *********************************************************************************************
// SuplaDevice.addRelay(5);
// SuplaDevice.addRollerShutterRelays(5, 13);
// SuplaDevice.setRollerShutterButtons(0, 14, 12);
// SuplaDevice.setRollerShutterFuncImpl(&supla_rs_SavePosition, &supla_rs_LoadPosition, &supla_rs_SaveSettings, &supla_rs_LoadSettings);
// SuplaDevice.addSensorNO(4);
SuplaDevice.addDS18B20Thermometer();
SuplaDevice.addDHT22();
SuplaDevice.addPressureSensor(); // cisnienie
SuplaDevice.addDistanceSensor();
// SuplaDevice.addRelayButton(5, 14, INPUT_TYPE_BTN_MONOSTABLE, 0, SUPLA_BIT_RELAYFUNC_LIGHTSWITCH);
//SuplaDevice.addRelayButton(13, 12, INPUT_TYPE_BTN_BISTABLE);
//*********************************************************************************************************
// Pokaz_zawartosc_eeprom();
read_guid();
int Location_id = read_supla_id().toInt();
strcpy(Supla_server, read_supla_server().c_str());
strcpy(Location_Pass, read_supla_pass().c_str());
SuplaDevice.setStatusFuncImpl(&status_func);
if (String(read_wifi_ssid().c_str()) == 0
|| String(read_wifi_pass().c_str()) == 0
|| String(read_login().c_str()) == 0
|| String(read_login_pass().c_str()) == 0
|| String(read_supla_server().c_str()) == 0
|| String(read_supla_id().c_str()) == 0
|| String(read_supla_pass().c_str()) == 0
) {
gui_color = GUI_GREEN;
Tryb_konfiguracji();
}
read_guid();
my_mac_adress();
SuplaDevice.setStatusFuncImpl(&status_func);
SuplaDevice.setName(SUPLA_DEVICE_NAME);
SuplaDevice.begin(GUID, // Global Unique Identifier
mac, // Ethernet MAC address
Supla_server, // SUPLA server address
Location_id, // Location ID
Location_Pass);
Serial.println();
Serial.println("Uruchamianie serwera...");
WiFi.mode(WIFI_STA);
createWebServer();
httpUpdater.setup(&httpServer, UPDATE_PATH, www_username, www_password);
httpServer.begin();
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
}
//*********************************************************************************************************
void loop() {
if (WiFi.status() != WL_CONNECTED) {
WiFi_up();
}
else httpServer.handleClient();
SuplaDevice.iterate();
}
//*********************************************************************************************************
// Supla.org ethernet layer
int supla_arduino_tcp_read(void *buf, int count) {
_supla_int_t size = client.available();
if ( size > 0 ) {
if ( size > count ) size = count;
return client.read((uint8_t *)buf, size);
};
return -1;
};
int supla_arduino_tcp_write(void *buf, int count) {
return client.write((const uint8_t *)buf, count);
};
bool supla_arduino_svr_connect(const char *server, int port) {
return client.connect(server, 2015);
}
bool supla_arduino_svr_connected(void) {
return client.connected();
}
void supla_arduino_svr_disconnect(void) {
client.stop();
}
void supla_arduino_eth_setup(uint8_t mac[6], IPAddress *ip) {
WiFi_up();
}
SuplaDeviceCallbacks supla_arduino_get_callbacks(void) {
SuplaDeviceCallbacks cb;
cb.tcp_read = &supla_arduino_tcp_read;
cb.tcp_write = &supla_arduino_tcp_write;
cb.eth_setup = &supla_arduino_eth_setup;
cb.svr_connected = &supla_arduino_svr_connected;
cb.svr_connect = &supla_arduino_svr_connect;
cb.svr_disconnect = &supla_arduino_svr_disconnect;
cb.get_temperature = &get_temperature;
cb.get_temperature_and_humidity = &get_temperature_and_humidity;
cb.get_rgbw_value = NULL;
cb.set_rgbw_value = NULL;
cb.get_pressure = get_pressure;
cb.get_distance= get_distance;
return cb;
}
//*********************************************************************************************************
void createWebServer() {
// My_mac = my_mac_adress();
httpServer.on("/", []() {
if (!httpServer.authenticate(www_username, www_password))
return httpServer.requestAuthentication();
httpServer.send(200, "text/html", supla_webpage_start(0));
});
httpServer.on("/set0", []() {
save_wifi_ssid(httpServer.arg("wifi_ssid"));
save_wifi_pass(httpServer.arg("wifi_pass"));
save_login( httpServer.arg("modul_login"));
save_login_pass(httpServer.arg("modul_pass"));
save_supla_server(httpServer.arg("supla_server"));
save_supla_hostname(httpServer.arg("supla_hostname"));
save_supla_id(httpServer.arg("supla_id"));
save_supla_pass(httpServer.arg("supla_pass"));
if (!httpServer.authenticate(www_username, www_password))
return httpServer.requestAuthentication();
httpServer.send(200, "text/html", supla_webpage_start(1));
});
//************************************************************
httpServer.on("/firmware_up", []() {
if (!httpServer.authenticate(www_username, www_password))
return httpServer.requestAuthentication();
httpServer.send(200, "text/html", supla_webpage_upddate());
});
//****************************************************************************************************************************************
httpServer.on("/reboot", []() {
if (!httpServer.authenticate(www_username, www_password))
return httpServer.requestAuthentication();
httpServer.send(200, "text/html", supla_webpage_start(2));
ESP.reset();
}
);
}
//****************************************************************************************************************************************
void Tryb_konfiguracji() {
supla_led_blinking(LED_CONFIG_PIN, 100);
my_mac_adress();
Serial.println("Tryb konfiguracji");
WiFi.disconnect();
delay(1000);
WiFi.mode(WIFI_AP);
WiFi.softAP(Config_Wifi_name, Config_Wifi_pass);
delay(1000);
Serial.println("Tryb AP");
createWebServer();
httpServer.begin();
Serial.println("Start Serwera");
Modul_tryb_konfiguracji = 2;
while (1) {
httpServer.handleClient();
}
}
void WiFi_up() {
// WiFi.setOutputPower(20.5);
supla_led_blinking(LED_CONFIG_PIN, 500);
WiFi.disconnect();
WiFi.hostname(String(read_supla_hostname().c_str()));
WiFi.softAPdisconnect(true);
String esid = String(read_wifi_ssid().c_str());
String epass = String(read_wifi_pass().c_str());
Serial.println("WiFi init");
Serial.print("SSID: ");
Serial.println(esid);
Serial.print("PASSWORD: ");
Serial.println(epass);
WiFi.mode(WIFI_STA);
WiFi.begin(esid.c_str(), epass.c_str());
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.print("\nlocalIP: ");
Serial.println(WiFi.localIP());
Serial.print("subnetMask: ");
Serial.println(WiFi.subnetMask());
Serial.print("gatewayIP: ");
Serial.println(WiFi.gatewayIP());
}
void first_start(void) {
EEPROM.begin(EEPROM_SIZE);
delay(100);
EEPROM.write(EEPROM_SIZE - 1, '1');
EEPROM.end();
delay(100);
save_login(DEFAULT_LOGIN);
save_login_pass(DEFAULT_PASSWORD);
save_supla_hostname(DEFAULT_HOSTNAME);
}
String read_rssi(void) {
long rssi = WiFi.RSSI();
return String(rssi) ;
}
void get_temperature_and_humidity(int channelNumber, double *temp, double *humidity) {
*temp = bme.readTemperature();
*humidity = bme.readHumidity();
if ( isnan(*temp) || isnan(*humidity) ) {
*temp = -275;
*humidity = -1;
}
}
double get_temperature(int channelNumber, double last_val) {
double t = -275;
if ( sensors.getDeviceCount() > 0 ) {
sensors.requestTemperatures();
t = sensors.getTempCByIndex(0);
}
return t;
}
double get_pressure(int channelNumber, double pressure) {
pressure = bme.readPressure() / 100.0F;
Serial.print("Pressure = ");
Serial.print(bme.readPressure()/100);
Serial.println(" hPa");
return pressure;
}
double get_distance(int channelNumber, double t) {
// float lux = analogRead(LIGHTSENSORPIN); //TEMT6000
double lux = LightSensor.GetLightIntensity(); //BH1750
t = abs(lux);
Serial.print("Natezenie swiatla = ");
Serial.print(LightSensor.GetLightIntensity());
delay(1250);
return t;
}
void supla_led_blinking_func(void *timer_arg) {
int val = digitalRead(LED_CONFIG_PIN);
digitalWrite(LED_CONFIG_PIN, val == HIGH ? 0 : 1);
}
void supla_led_blinking(int led, int time) {
os_timer_disarm(&led_timer);
os_timer_setfn(&led_timer, supla_led_blinking_func, NULL);
os_timer_arm (&led_timer, time, true);
}
void supla_led_blinking_stop(void) {
os_timer_disarm(&led_timer);
digitalWrite(LED_CONFIG_PIN, 0);
}
void supla_led_set(int ledPin) {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, 1);
}
