Wielkie dzięki za poprawę koduwojtas567 pisze: ↑pn lip 09, 2018 10:19 ambrakuje Ci biblioteki <ArduinoJson.h>
poprawiłem też termometry bo miałeś za dużo kodu chyba, że będziesz używał czujnika pyłu ale to i tak by nie działał jeszcze.
Kod: Zaznacz cały
#include <FS.h> #include <ESP8266WiFi.h> #define SUPLADEVICE_CPP #include <SuplaDevice.h> #include <ESP8266WebServer.h> #include <DNSServer.h> #include <WiFiManager.h> #include <ArduinoJson.h> #include <OneWire.h> #include <DallasTemperature.h> int button1 = 0; //wartosc początkowa dla przycisku 1 WiFiClient client; OneWire oneWire(4); // (D2) - Pin number DallasTemperature sensors(&oneWire); DeviceAddress garaz = { 0x28, 0xFF, 0x2E, 0xFB, 0xC1, 0x17, 0x1, 0xD3 }; // odczytany adres 28FF2EFBC11701D3 DeviceAddress zewnatrz = { 0x28, 0xFF, 0xEC, 0xFE, 0xC1, 0x17, 0x1, 0xF3 }; //Odczytany adres 28FFECFEC11701F3 //define your default values here, if there are different values in config.json, they are overwritten. //length should be max size + 1 char Supla_server[40]; char Location_id[15]; char Location_Pass[20]; byte mac[6]; //flag for saving data bool shouldSaveConfig = false; bool initialConfig = false; #define TRIGGER_PIN D3 int timeout = 120; // szas otwarica config po resecie ESP //callback notifying us of the need to save config void saveConfigCallback () { Serial.println("Should save config"); shouldSaveConfig = true; } void ondemandwifiCallback () { // The extra parameters to be configured (can be either global or just in the setup) // After connecting, parameter.getValue() will get you the configured value // id/name placeholder/prompt default length WiFiManagerParameter custom_Supla_server("server", "supla server", Supla_server, 40); WiFiManagerParameter custom_Location_id("ID", "Location_id", Location_id, 15); WiFiManagerParameter custom_Location_Pass("Password", "Location_Pass", Location_Pass, 20); //WiFiManager //Local intialization. Once its business is done, there is no need to keep it around WiFiManager wifiManager; //set config save notify callback wifiManager.setSaveConfigCallback(saveConfigCallback); //add all your parameters here wifiManager.addParameter(&custom_Supla_server); wifiManager.addParameter(&custom_Location_id); wifiManager.addParameter(&custom_Location_Pass); //set minimu quality of signal so it ignores AP's under that quality //defaults to 8% wifiManager.setMinimumSignalQuality(); // set configportal timeout wifiManager.setConfigPortalTimeout(timeout); if (!wifiManager.startConfigPortal("SuplaAP")) { Serial.println("failed to connect and hit timeout"); delay(3000); //reset and try again, or maybe put it to deep sleep ESP.restart(); delay(5000); } //if you get here you have connected to the WiFi Serial.println("connected...yeey :)"); //read updated parameters strcpy(Supla_server, custom_Supla_server.getValue()); strcpy(Location_id, custom_Location_id.getValue()); strcpy(Location_Pass, custom_Location_Pass.getValue()); } // DS18B20 Sensor read implementation double get_temperature(int channelNumber, double last_val) { double t = -275; if ( sensors.getDeviceCount() > 0 ) { sensors.requestTemperatures(); switch(channelNumber) { case 0: t = sensors.getTempC(garaz); break; case 1: t = sensors.getTempC(zewnatrz); break; }; }; return t; } void setup() { Serial.begin(115200); pinMode (16, INPUT_PULLUP); //ustawiamy Pin 16 (D0) na przycisk // Init DS18B20 library sensors.begin(); // Set temperature callback SuplaDevice.setTemperatureCallback(&get_temperature); pinMode(TRIGGER_PIN, INPUT); if (WiFi.SSID()==""){ //Serial.println("We haven't got any access point credentials, so get them now"); initialConfig = true; } //read configuration from FS json Serial.println("mounting FS..."); if (SPIFFS.begin()) { Serial.println("mounted file system"); if (SPIFFS.exists("/config.json")) { //file exists, reading and loading Serial.println("reading config file"); File configFile = SPIFFS.open("/config.json", "r"); if (configFile) { Serial.println("opened config file"); size_t size = configFile.size(); // Allocate a buffer to store contents of the file. std::unique_ptr<char[]> buf(new char[size]); configFile.readBytes(buf.get(), size); DynamicJsonBuffer jsonBuffer; JsonObject& json = jsonBuffer.parseObject(buf.get()); json.printTo(Serial); if (json.success()) { // Serial.println("\nparsed json"); strcpy(Supla_server, json["Supla_server"]); strcpy(Location_id, json["Location_id"]); strcpy(Location_Pass, json["Location_Pass"]); } else { Serial.println("failed to load json config"); } } } WiFi.softAPdisconnect(true); // wyłączenie rozglaszania Wifi ESP po połaczeniu do lokalnego WIFI } else { Serial.println("failed to mount FS"); } //end read //Serial.println(Location_id); //Serial.println(Location_Pass); //Serial.println(Supla_server); delay(10); char GUID[SUPLA_GUID_SIZE] ={0x53,0x9C,0x2D,0x21,0x2F,0xB2,0xB9,0x40,0x71,0xAD,0xA8,0xCD,0x39,0xC7,0x34,0x4D}; // with GUID that you can retrieve from https://www.supla.org/arduino/get-guid. WiFi.macAddress(mac); // CHANNEL0 - Thermometer DS18B20 SuplaDevice.addDS18B20Thermometer(); // CHANNEL1 - Thermometer DS18B20 SuplaDevice.addDS18B20Thermometer(); // CHANNEL2 - RELAY SuplaDevice.addRelay(D5, true); // CHANNEL3 - RELAY SuplaDevice.addRelay(D6, true); // CHANNEL4 - RELAY SuplaDevice.addRelay(D7, true); // CHANNEL5 - Opening sensor (Normal Open) SuplaDevice.addSensorNO(A0); // A0 - Pin number where the sensor is connected // Call SuplaDevice.addSensorNO(A0, true) with an extra "true" parameter // to enable the internal pull-up resistor // CHANNEL6 - DHT22 Sensor // SuplaDevice.addDHT11(); // SuplaDevice.addAM2302(); // SuplaDevice.addDHT22(); int LocationID = atoi(Location_id); SuplaDevice.begin(GUID, // Global Unique Identifier mac, // Ethernet MAC address Supla_server, // SUPLA server address LocationID, // Location ID Location_Pass); // Location Password } void loop() { // is configuration portal requested? if ( digitalRead(TRIGGER_PIN) == LOW|| (initialConfig)) { ondemandwifiCallback () ; initialConfig = false; } //save the custom parameters to FS if (shouldSaveConfig) { Serial.println("saving config"); DynamicJsonBuffer jsonBuffer; JsonObject& json = jsonBuffer.createObject(); json["Supla_server"] = Supla_server; json["Location_id"] = Location_id; json["Location_Pass"] = Location_Pass; File configFile = SPIFFS.open("/config.json", "w"); if (!configFile) { Serial.println("failed to open config file for writing"); } json.prettyPrintTo(Serial); json.printTo(configFile); configFile.close(); Serial.println("config saved"); shouldSaveConfig = false; //end save } if (WiFi.status() != WL_CONNECTED) { WiFi_up(); } SuplaDevice.iterate(); TSD_SuplaChannelNewValue przycisk1; //ustaw nazwe dla przycisku przycisk1.SenderID = 0; // Powiadom clouda, że załączasz recznie. W przypadku siłowników ma być 0 przycisk1.ChannelNumber = 4; // nr kanału przekaźnika przycisk1.DurationMS = 0; //czas wlaczenia button1 = digitalRead(16); if(digitalRead(16)==LOW){ // tu dodajemy jeszcze raz zeby nie pstrykalo samo czyli przerwa i ponowne zapytanie delay(100); if(digitalRead(16)==LOW){ przycisk1.value[0] = !przycisk1.value[0]; SuplaDevice.channelSetValue(&przycisk1); while(digitalRead(16)==LOW); delay(20); } } } // 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 = NULL; cb.get_rgbw_value = NULL; cb.set_rgbw_value = NULL; return cb; } void WiFi_up() // Procedimiento de conexión para redes WiFi { Serial.print("Conexión a la red "); // Serial.println(ssid); WiFi.begin(); // Intentar conectarse a la red for (int x = 60; x > 0; x--) { if (WiFi.status() == WL_CONNECTED) { break; } else { Serial.print("."); delay(500); } } if (WiFi.status() == WL_CONNECTED) { Serial.println(""); Serial.println("Conexión hecha"); Serial.println("Adres IP: "); Serial.print(WiFi.localIP()); Serial.print(" / "); Serial.println(WiFi.subnetMask()); Serial.print("puerta: "); Serial.println(WiFi.gatewayIP()); long rssi = WiFi.RSSI(); Serial.print("Fuerza de la señal (RSSI): "); Serial.print(rssi); Serial.println(" dBm"); } else { Serial.println(""); Serial.println("La conexión no pudo hacerse"); } }
Bibliotekę mam , ale zastanawia mnie, czy rodzaj płytki ma znaczenie, gdyż program z postu wyżej od kolegi elmaya wywala mi się w tym samym miejscu. Płytkę mam ustawioną na NodeMcu 1.0