Supla ESP wifi manager i aktualizacja przez wifi
Wojtas567 wyciągnąłem dziś w końcu moduł poduszkowy InCan żeby wgrać soft z Arduino online, ale jak przy obsłudze przycisków wpisuję zero (przycisk monostabilny) to nic się nie dzieje. Jak wpiszę jakąś liczbę to faktycznie włącza się światło na te kilkanaście sekund. Co tu jest nie tak? Druga sprawa to jeżeli nawet by działało to jeżeli wyłączę przez Apkę to włączę przyciskiem klikając tylko raz czy muszę rozewrzeć styki i znowu zewrzeć czyli klikać 2 razy?
Code: Select all
#include <ESP8266WiFi.h>
#define SUPLADEVICE_CPP
#include <SuplaDevice.h>
#include <ESP8266WebServer.h>
#include <DNSServer.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPUpdateServer.h>
extern "C" {
#include "user_interface.h"
}
// Include the libraries we need
#include <DHT.h>
#define DHTPIN 1
#define DHTTYPE DHT22
// Setup a DHT instance
DHT dht(DHTPIN, DHTTYPE);
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE 2
#define TEMPERATURE_PRECISION 10 // rozdzielczość czujnika DS 9 -12 bit
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
ADC_MODE(ADC_VCC);
#define BTN_COUNT 2
// Setup Supla connection
const char* ssid = "xxxxx";
const char* password = "xxxxx";
WiFiClient client;
const char* host = "supla";
const char* update_path = "/supla";
const char* update_username = "admin";
const char* update_password = "supla";
ESP8266WebServer httpServer(81);
ESP8266HTTPUpdateServer httpUpdater;
// DS18B20 Sensor read implementation
double get_temperature(int channelNumber, double last_val) {
double t = -275;
switch(channelNumber)
{
case 0:
sensors.requestTemperatures();
t = sensors.getTempCByIndex(0);
Serial.println(t);
break;
case 1:
t = WiFi.RSSI();
Serial.println(t);
break;
}
return t;
}
// obsługa przycisków
typedef struct {
int pin;
int relay_pin;
int channel;
int ms;
char last_val;
unsigned long last_time;
} _btn_t;
_btn_t btn[BTN_COUNT];
void supla_timer() {
char v;
unsigned long now = millis();
for(int a=0;a<BTN_COUNT;a++)
if (btn[a].pin > 0) {
v = digitalRead(btn[a].pin);
if (v != btn[a].last_val && now - btn[a].last_time ) {
btn[a].last_val = v;
btn[a].last_time = now;
if (v==0)
{
if ( btn[a].ms > 0 ) {
SuplaDevice.relayOn(btn[a].channel, btn[a].ms);
} else {
if ( digitalRead(btn[a].relay_pin) == 0 ) {
SuplaDevice.relayOff(btn[a].channel);
Serial.print("BTN Switsh off relay ");
Serial.println(btn[a].relay_pin);
} else {
SuplaDevice.relayOn(btn[a].channel, 0);
Serial.print("BTN Switsh on relay ");
Serial.println(btn[a].relay_pin);
}
}
}
}
}
}
void supla_btn_init() {
for(int a=0;a<BTN_COUNT;a++)
if (btn[a].pin > 0) {
pinMode(btn[a].pin, INPUT_PULLUP);
btn[a].last_val = digitalRead(btn[a].pin);
btn[a].last_time = millis();
}
}
// DHT22 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;
}
}
void setup() {
Serial.begin(115200);
delay(10);
wifi_station_set_hostname("Supla-Salon"); //nazwa w sieci lokalnej
WiFi.softAPdisconnect(true); // wyłączenie rozgłaszania sieci ESP
// Inicjalizacja DS18B20
sensors.begin();
SuplaDevice.setTemperatureCallback(&get_temperature);
// Init DHT library
dht.begin();
// Set temperature/humidity callback
SuplaDevice.setTemperatureHumidityCallback(&get_temperature_and_humidity);
// Replace the falowing GUID
uint8_t mac[WL_MAC_ADDR_LENGTH];
WiFi.macAddress(mac);
char GUID[SUPLA_GUID_SIZE] = {0xD9,0xC6,0x7D,0x4F,0xE2,0xC2,0x49,0xEA,0x90,0x37,0x0D,0xD5,0x02,0x1A,0x3E,0x33};
// with GUID that you can retrieve from https://www.supla.org/arduino/get-guid
// CHANNEL0,1 DS
SuplaDevice.addDS18B20Thermometer(); // DS
SuplaDevice.addDS18B20Thermometer(); //wifi
// CHANNEL2 - DHT22
SuplaDevice.addDHT22(); // DHT22
// CHANNEL3,4 - RELAY
SuplaDevice.addRelay(5); // zalacza pompa na grzejniki D1
SuplaDevice.addRelay(13); // zalacza pompa na grzejniki D7
// CHANNEL5,6 - Opening sensor (Normal Open)
SuplaDevice.addSensorNO(4); // A0 - Pin number where the sensor is connected
SuplaDevice.addSensorNO(16); // Call SuplaDevice.addSensorNO(A0, true) with an extra "true" parameter
// to enable the internal pull-up resistor
memset(btn, 0, sizeof(btn));
btn[0].pin =14; // pin gpio button D5
btn[0].relay_pin =5; // pin gpio on which is relay D1
btn[0].channel =3; // supla channel
btn[0].ms =0; // if = 0 Bistable -- if > 0 Monostable for X ms
btn[1].pin =12; // pin gpio button D6
btn[1].relay_pin =13; // pin gpio on which is relay D2
btn[1].channel =4; // supla channel
btn[1].ms =0; // if = 0 Bistable -- if > 0 Monostable for X ms
supla_btn_init();
SuplaDevice.setTimerFuncImpl(&supla_timer);
SuplaDevice.setName("Salon");
SuplaDevice.begin(GUID, // Global Unique Identifier
mac, // Ethernet MAC address
"192.168.1.108", // SUPLA server address
1, // Location ID
"xxx"); // 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", 81);
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() {
SuplaDevice.iterate();
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) {
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_temperature = &get_temperature;
return cb;
}
-
- Posts: 66
- Joined: Thu Jun 28, 2018 4:21 am
A jest jakaś opcja, aby tak zmodyfikować firmware, aby ze stronki http://supla.local:81/nowy wejść do WifiManagera? chodzi mi o to aby nie trzeba naciskać fizyczny przycisk tylko po wprowadzeniu hasła wejść do WifiManagera.wojtas567 wrote: ↑Thu Sep 06, 2018 12:13 pmAktualizacja przez www
W przeglądarce możemy spróbować wprowadzić adres: http://supla.local:81/nowy lub IP modułu np: http://192.168.0.123:81/nowy
Nazwa użytkownika i hasło: admin, supla