Supla ESP wifi manager i aktualizacja przez wifi
-
cino111
- Posts: 714
- Joined: Mon May 07, 2018 8:00 pm
Ok, a moge wszystkie softy wgrywac jak dałem na scr? Nie musiałbym zastanawiać się przy każdej płytce jakie miałem ustawienia.
-
wojtas567
- Posts: 2334
- Joined: Sun Apr 03, 2016 7:16 pm
- Location: Olsztyn
Możesz spróbować wgrać i powinno działać, tylko jezeli chcesz aktualizować przez www to od razu sprawdź czy będą działać Ci aktualizacje na tych ustawieniach.
Pozdrawiam
Wojtek
Wojtek
-
cino111
- Posts: 714
- Joined: Mon May 07, 2018 8:00 pm
Wgrałem twój soft do SONOFFa, ale na SPI MODE ustawione na DOUT. Inaczej nie pokazywało się WIFI.
Na cloudzie rejestruje sie po kilku minutach. Włączenie przekaźnika w apce fizycznie załącza się po bardzo długim czasie. Klikając włącz, wyłącz kilka razy fizycznie łapie po kilkudziesięciu sekundach i wykonuje wszystkie operacje na raz.
Tak myślę, że przed wgraniem na DOUT nie wyczyściłem modułu - czy zaczytanie softu przez www czyści moduł? Powinienem podpiąć fizycznie i wyczyścić najpierw ESP?
Na cloudzie rejestruje sie po kilku minutach. Włączenie przekaźnika w apce fizycznie załącza się po bardzo długim czasie. Klikając włącz, wyłącz kilka razy fizycznie łapie po kilkudziesięciu sekundach i wykonuje wszystkie operacje na raz.
Tak myślę, że przed wgraniem na DOUT nie wyczyściłem modułu - czy zaczytanie softu przez www czyści moduł? Powinienem podpiąć fizycznie i wyczyścić najpierw ESP?
-
wojtas567
- Posts: 2334
- Joined: Sun Apr 03, 2016 7:16 pm
- Location: Olsztyn
nie bawiłem się na DOUT więc trudno mi powiedzieć jakie będą problemy lub nie 
Jak wyczyścisz pamięć przed aktualizacją przez www to już nie zadziała ta aktualizacja.
Czyścić należy przed wgraniem softu przez TX,RX a zwłaszcza jeżeli zmieniamy zupełnie na inny.
Jeżeli masz takie opóźnienia to coś jest nie tak, a wgrywałeś do tego sonoffa inny soft, jak pracował?
Jak wyczyścisz pamięć przed aktualizacją przez www to już nie zadziała ta aktualizacja.
Czyścić należy przed wgraniem softu przez TX,RX a zwłaszcza jeżeli zmieniamy zupełnie na inny.
Jeżeli masz takie opóźnienia to coś jest nie tak, a wgrywałeś do tego sonoffa inny soft, jak pracował?
Pozdrawiam
Wojtek
Wojtek
-
cino111
- Posts: 714
- Joined: Mon May 07, 2018 8:00 pm
Dobra śmiga 
Wgrałem bezpośrednio z Arduino IDE na ponizszych ustawieniach. Bład miałem pewnie dlatego, ze skompilowałeś plik na DIO, a ja wgrywałem na DOUT
Swoja drogą to jak te parametry ustawić, bo trochę zrobiłem to na czuja.
Wgrałem bezpośrednio z Arduino IDE na ponizszych ustawieniach. Bład miałem pewnie dlatego, ze skompilowałeś plik na DIO, a ja wgrywałem na DOUT
Swoja drogą to jak te parametry ustawić, bo trochę zrobiłem to na czuja.
You do not have the required permissions to view the files attached to this post.
-
wojtas567
- Posts: 2334
- Joined: Sun Apr 03, 2016 7:16 pm
- Location: Olsztyn
U mnie prawie na każdych działało, ważne że jeżeli będziesz chciał robić aktualizacje to musisz trzymać się tych samych.
Pozdrawiam
Wojtek
Wojtek
-
cino111
- Posts: 714
- Joined: Mon May 07, 2018 8:00 pm
A mozna to zrobić dla Arduino Mega? Pewnie trzeba usunąć z kodu pozycje z WiFi, ale biblioteki są dla ESP, wiec nie wiem.
-
wojtas567
- Posts: 2334
- Joined: Sun Apr 03, 2016 7:16 pm
- Location: Olsztyn
Musisz pozmieniać też nr wejść/wyjść, czy i jak to będzie działać na mega nie wiem.
Łatwiej chyba będzie zacząć od zera.
Łatwiej chyba będzie zacząć od zera.
Pozdrawiam
Wojtek
Wojtek
-
wojtas567
- Posts: 2334
- Joined: Sun Apr 03, 2016 7:16 pm
- Location: Olsztyn
Udało mi się rozszerzyć kod GUID w stosunku do mac adresu do testowania poniżej kod wystarczy zastąpić linijki GUID i mac
Code: Select all
// Replace the falowing GUID
uint8_t mac[WL_MAC_ADDR_LENGTH];
WiFi.macAddress(mac);
char GUID[SUPLA_GUID_SIZE] = {mac[WL_MAC_ADDR_LENGTH - 6],
mac[WL_MAC_ADDR_LENGTH - 5],
mac[WL_MAC_ADDR_LENGTH - 4],
mac[WL_MAC_ADDR_LENGTH - 3],
mac[WL_MAC_ADDR_LENGTH - 2],
mac[WL_MAC_ADDR_LENGTH - 1]};
Pozdrawiam
Wojtek
Wojtek
-
cino111
- Posts: 714
- Joined: Mon May 07, 2018 8:00 pm
Wgrywam soft do ESP-01 i nie loguje się do clouda. W sieci jest widoczny i mogę na niego wejść. Co możne być przyczyną, że nie ma go w cloudzie? Mam jakiś błąd w kodzie? Jak wgram podstawowy soft (z wpisaniem wszystkich parametrów bezpośrednio w kodzie) to loguje się do clouda bez problemu.
Code: Select all
#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 <ESP8266mDNS.h>
#include <ESP8266HTTPUpdateServer.h>
extern "C" {
#include "user_interface.h"
}
#include <DHT.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//-----------------------------serwer,WIFI, AP-------------------------------
ADC_MODE(ADC_VCC);
#define BTN_COUNT 15
WiFiClient client;
const char* host = "supla";
const char* update_path = "/nowy";
const char* update_username = "admin";
const char* update_password = "supla";
ESP8266WebServer httpServer(81);
ESP8266HTTPUpdateServer httpUpdater;
//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 0
int timeout = 120; // seconds to run for
//callback notifying us of the need to save config
void saveConfigCallback () {
Serial.println("Powinien zapisać konfigurację");
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("SuplaESP_Cino111")) {
Serial.println("nie udało się połączyć w osiągniętym limicie czasu");
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("połaczono... :)");
//read updated parameters
strcpy(Supla_server, custom_Supla_server.getValue());
strcpy(Location_id, custom_Location_id.getValue());
strcpy(Location_Pass, custom_Location_Pass.getValue());
}
// ----------------------------czujnik DHT----------------------------------
#define DHTPIN 2
#define DHTTYPE DHT11
// Setup a DHT instance
DHT dht(DHTPIN, DHTTYPE);
// DS18B20 Sensor read implementation
void get_temperature_and_humidity(int channelNumber, double *temp, double *humidity) {
*temp = dht.readTemperature();
*humidity = dht.readHumidity();
if ( isnan(*temp) || isnan(*humidity) ) {
*temp = -275;
*humidity = -1;
}
}
//--------------------------czujnik DS18B20-------------------
// Setup a oneWire instance
OneWire oneWire(1); // 1 - Pin number
// Pass oneWire reference to Dallas Temperature
DallasTemperature sensors(&oneWire);
// DS18B20 Sensor read implementation
double get_temperature(int channelNumber, double last_val) {
double t = -275;
switch(channelNumber)
{
case 1:
if ( sensors.getDeviceCount() > 0 )
{
sensors.requestTemperatures();
t = sensors.getTempCByIndex(0);
}
break;
case 2:
t = WiFi.RSSI();
break;
case 3:
t = (ESP.getVcc()/1000.0);
break;
case 4:
t = (ESP.getFlashChipRealSize()/1024/1024);
break;
};
return t;
}
void setup() {
Serial.begin(115200);
delay(10);
wifi_station_set_hostname("Supla_ESP01DHT11"); //nazwa w sieci lokalnej
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("adaptacja FS...");
if (SPIFFS.begin()) {
Serial.println("ładowanie plików systemu");
if (SPIFFS.exists("/config.json")) {
//file exists, reading and loading
Serial.println("odczyt pliku konfiguracyjnego");
File configFile = SPIFFS.open("/config.json", "r");
if (configFile) {
Serial.println("otwarty plik konfiguracji");
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());
Serial.println(jsonBuffer.size());
json.printTo(Serial);
if (json.success()) {
Serial.println("\njson przeanalizowany");
strcpy(Supla_server, json["Supla_server"]);
strcpy(Location_id, json["Location_id"]);
strcpy(Location_Pass, json["Location_Pass"]);
} else {
Serial.println("nie udało się załadować konfiguracji json");
}
}
}
} else {
Serial.println("nie udało się zaadaptować FS");
}
WiFi.mode(WIFI_STA); // Force to station mode because if device was switched off while in access point mode it will start up next time in access point mode.
// Init DS18B20 library
sensors.begin();
// Set temperature callback
SuplaDevice.setTemperatureCallback(&get_temperature);
// Init DHT library
dht.begin();
// Set temperature/humidity callback
SuplaDevice.setTemperatureHumidityCallback(&get_temperature_and_humidity);
delay(10);
// Replace the falowing GUID
char GUID[SUPLA_GUID_SIZE] = {0x18,0x09,0x05,0x01,ESP.getChipId()};
WiFi.macAddress(mac);
/*
* 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.
*/
SuplaDevice.addDHT11();
SuplaDevice.addDS18B20Thermometer();
SuplaDevice.setName("supla ESP01");
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
Serial.println();
Serial.println("Uruchamianie serwera aktualizacji...");
WiFi.mode(WIFI_STA);
MDNS.begin(host);
httpUpdater.setup(&httpServer, update_path, update_username, update_password);
httpServer.begin();
MDNS.addService("http", "tcp", 80);
Serial.printf("HTTPUpdateServer ready! Open http://%s.local%s in your browser and login with username '%s' and password '%s'\n", host, update_path, update_username, update_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("zapisywanie konfiguracji");
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("nie udało się otworzyć pliku konfiguracyjnego do zapisu");
}
json.prettyPrintTo(Serial);
json.printTo(configFile);
configFile.close();
Serial.println("konfiguracia zapisana");
shouldSaveConfig = false;
//end save
}
if (WiFi.status() != WL_CONNECTED)
{
WiFi_up();
}
SuplaDevice.iterate();
SuplaDevice.setTemperatureHumidityCallback(&get_temperature_and_humidity);
SuplaDevice.setTemperatureCallback(&get_temperature);
httpServer.handleClient();
}
// 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;
return cb;
}
void WiFi_up() // Procedimiento de conexión para redes WiFi
{
Serial.print("Łączenie z siecią ");
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("Połączono z");
Serial.println("Adres IP: ");
Serial.print(WiFi.localIP());
Serial.print(" / ");
Serial.println(WiFi.subnetMask());
Serial.print("geteway: ");
Serial.println(WiFi.gatewayIP());
long rssi = WiFi.RSSI();
Serial.print("siła sygnału (RSSI): ");
Serial.print(rssi);
Serial.println(" dBm");
}
else
{
Serial.println("");
Serial.println("brak połączenia");
}
}
