Włącznik

Awatar użytkownika
lesny8
Posty: 2808
Rejestracja: pn gru 11, 2017 9:43 pm

dogu18 pisze: sob sie 03, 2019 9:17 pm co to jest i co to robi??
Wtyczka na kabel do urządzenia, które chcesz mieć pod kontrolą SUPLI. Włączasz i wyłączasz urządzenie lokalnie z przycisku lub z app, harmonogramów itd.
Czekam na kolejne Supla Offline Party 👍
Awatar użytkownika
QLQ
Posty: 2276
Rejestracja: ndz wrz 03, 2017 9:13 am
Lokalizacja: Koszalin

Obecny brak czasu , nie mam kiedy tego zlozyc. Moze pod koniec tygodnia.
jak coś nie działa to włącz zasilanie.....
Awatar użytkownika
QLQ
Posty: 2276
Rejestracja: ndz wrz 03, 2017 9:13 am
Lokalizacja: Koszalin

Prace trwają.
Przekaźnik - cewka 3V, tranzystor NPN BC817, dioda 1n4148, rezystory 4,7k oraz 10k, esp07, button mono - pojemnościowy - zrobię potem fotkę elementów

Kod jest - wg PrimaryGUI - ale jest jedno ale : nie działa mi przełączanie jak nie ma wifi - czy też jak esp nie jest zalogowane . Poniżej kod. Pomóżcie proszę - co tam zmienić. :

Kod: Zaznacz cały

/* *************************************************************************
 *  
 * 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 <OneWire.h>
#include <DallasTemperature.h>
#include <DHT.h>

#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);
  EEPROM.begin(EEPROM_SIZE);
//  dht.begin();
 // sensors.begin();

  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.addRelayButton(5, 14, INPUT_TYPE_BTN_MONOSTABLE, 0, SUPLA_BIT_RELAYFUNC_LIGHTSWITCH);
     
     
     SuplaDevice.addRelayButton(13, 12, INPUT_TYPE_BTN_MONOSTABLE);   // pin przekaźnika gpio13, przycisk monostab na gpio12

  //*********************************************************************************************************

  //  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();

}

//*********************************************************************************************************

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 = NULL; //&get_temperature;
//  cb.get_temperature_and_humidity = NULL; // &get_temperature_and_humidity;
//  cb.get_rgbw_value = NULL;
//  cb.set_rgbw_value = NULL;

  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 = dht.readTemperature();
//  *humidity = dht.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;
//}

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);
}
IMG_20190810_115122.jpg
IMG_20190810_115122.jpg (178.46 KiB) Przejrzano 3282 razy
IMG_20190810_115942.jpg
IMG_20190810_115942.jpg (253.19 KiB) Przejrzano 3276 razy
jak coś nie działa to włącz zasilanie.....
Awatar użytkownika
QLQ
Posty: 2276
Rejestracja: ndz wrz 03, 2017 9:13 am
Lokalizacja: Koszalin

Już działa , wymaga dopracowania - szczegóły w filmie
Godz. 18:00 właśnie wrzucam filmik z działania: https://youtu.be/JfncCmilNF0 za 5 min powinien być dostępny.
.
Soft i biblioteki (made in @Espablo - PrimaryGUI - bez termometrów ):
Wlacznik_Supla.rar
(284.21 KiB) Pobrany 207 razy
jak coś nie działa to włącz zasilanie.....
Awatar użytkownika
Daro1003
Posty: 114
Rejestracja: pt sty 18, 2019 6:22 am

Coś mi nie kompiluje nie wiem dla czego - jestem zielony w środowisko arduino proszę o pomoc i wyrozumiałość,
Załadowałem wszystkie biblioteki.
Załączniki
Kompilacja.png
Kompilacja.png (20.74 KiB) Przejrzano 3170 razy
Biblioteki.png
Biblioteki.png (43.92 KiB) Przejrzano 3170 razy
Awatar użytkownika
QLQ
Posty: 2276
Rejestracja: ndz wrz 03, 2017 9:13 am
Lokalizacja: Koszalin

Chłopaki powrócę do pytania (kod powyżej ):
... nie działa mi przełączanie jak nie ma wifi - czy też jak esp nie jest zalogowane . Pomóżcie proszę - co tam zmienić. o co kaman ? :
jak coś nie działa to włącz zasilanie.....
elmaya
Posty: 1482
Rejestracja: śr cze 27, 2018 5:48 pm
Lokalizacja: El Saucejo - Sevilla

QLQ pisze: ndz lis 17, 2019 8:21 pm Chłopaki powrócę do pytania (kod powyżej ):
... nie działa mi przełączanie jak nie ma wifi - czy też jak esp nie jest zalogowane . Pomóżcie proszę - co tam zmienić. o co kaman ? :
blocking loop

Kod: Zaznacz cały

while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
try this:

Kod: Zaznacz cały

//while (WiFi.status() != WL_CONNECTED) {
    //delay(500);
   // Serial.print(".");
   //}
  yield();
krycha88
Posty: 5186
Rejestracja: pt lis 16, 2018 7:25 am
Kontakt:

QLQ pisze: ndz lis 17, 2019 8:21 pm Chłopaki powrócę do pytania (kod powyżej ):
... nie działa mi przełączanie jak nie ma wifi - czy też jak esp nie jest zalogowane . Pomóżcie proszę - co tam zmienić. o co kaman ? :
Musisz zastosować kod który poprawiłem, na Primary GUI przycisk nie działał bez wifi.

viewtopic.php?f=11&t=5233
https://gui-generic-builder.supla.io/
Awatar użytkownika
ktsurma
Posty: 162
Rejestracja: pn lis 18, 2019 7:07 pm
Lokalizacja: Zgierz

QLQ pisze: sob sie 10, 2019 4:01 pm Już działa , wymaga dopracowania - szczegóły w filmie
Godz. 18:00 właśnie wrzucam filmik z działania: https://youtu.be/JfncCmilNF0 za 5 min powinien być dostępny.
.
Soft i biblioteki (made in @Espablo - PrimaryGUI - bez termometrów ): Wlacznik_Supla.rar
Bardzo fajna rzecz. Na początek szukam podobnego ale do włączania nożnego. Coś na kształt PNW - 01 od Zamel-a. Tam ta cena jest zaporowa.
Awatar użytkownika
QLQ
Posty: 2276
Rejestracja: ndz wrz 03, 2017 9:13 am
Lokalizacja: Koszalin

ktsurma pisze: pt lis 22, 2019 8:12 pm
QLQ pisze: sob sie 10, 2019 4:01 pm Już działa , wymaga dopracowania - szczegóły w filmie
Godz. 18:00 właśnie wrzucam filmik z działania: https://youtu.be/JfncCmilNF0 za 5 min powinien być dostępny.
.
Soft i biblioteki (made in @Espablo - PrimaryGUI - bez termometrów ): Wlacznik_Supla.rar
Bardzo fajna rzecz. Na początek szukam podobnego ale do włączania nożnego. Coś na kształt PNW - 01 od Zamel-a. Tam ta cena jest zaporowa.
Miałem tą przyjemność, że PNW-01 wygrałem w konkursie ZAMEL z własnym grawerem :)
jak coś nie działa to włącz zasilanie.....
ODPOWIEDZ

Wróć do „Projekty użytkowników”