Linki bezpośrednie sterowane gestami

Masz pomysł na funkcjonalność lub koncepcję na rozwój projektu. Opisz wszystko tutaj.
cino111
Posty: 714
Rejestracja: pn maja 07, 2018 8:00 pm

Ja tylko poprosiłem Elmaya, żeby link bezpośredni dodał mi do standardowego kodu Supli.
Tu jest poprawiony kod, bo w powyższym coś miałem nie tak. Wpisujesz swój SSID i Hasło do wifi, podajesz swoje namiary do serwera Supli (ja mam nr IP, bo mam swoją instancję) i wgrywasz. Ja wgrywam do Wemos D1. Jak mozesz wyczytać z kodu na GPIO02 mam podłaczony termometr DS18B20, gdzie na drugim termometrze w cloud pokazany jest zasięg WIFI, na GPIO04 czujnik wilgotności i temperatury DHT22, na GPIO05,12,13 przekaźniki, no i Elmay dołożył mi jeszcze pod GPIO14 link bezpośredni pod przycisk bistabilny. Tym przyciskiem uruchamiam pompę obiegową ciepłej wody która jest podłączona do innego modułu i zeby nie ciągnąć kabla 15m uruchamiam ją na 30s linkiem bezpośrednim. Aaaa program wgrywasz poprzez Arduino Ide.
Coś pięknego :D Jeszcze raz Elamy dziękuje za pomoc. Taki pomieszany program daje dużo więcej możliwości, niż tylko same linki. Musiał bym upchać w puszce 2 moduły - jeden do sterowania suplą a drugi do jednego linka bezpośredniego. Teraz mam dużo więcej miejsca.
Jak ktoś ma chwilę (może Elmay) to fajnie by było zrobić jeszcze config do wprowadzenia danych serwera supli :mrgreen:

Kod: Zaznacz cały



#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 4
#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);


#define Link_1_PIN 14 //D5                  bistable switch in Gpio14 (D5) ---- przełącznik bistabilny w Gpio14 (D5)
const char* host2 = "192.168.1.1";  //  the url of your server or the IP --- adres URL twojego serwera lub IP
String url = "/direct/6/GNBxxxxxZmVDZ/turn-on";//  -----  Direct Link https://moduly.ddns.net/direct/6/GNBjYMiGZmVDZ/turn-on
const int httpsPort = 443;  //              https port modify if necessary
bool last_1 = false;
 


// Setup Supla connection
const char* ssid     = "Marcin_S8";
const char* password = "haslo";


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;

// Obsługa czujnika DHT22 lub BME280 itp
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;
    }
}


// DS18B20 Sensor read implementation
double get_temperature(int channelNumber, double last_val) {

    double t = -275;
          switch(channelNumber)
         {

            case 1:
         sensors.requestTemperatures();
         t = sensors.getTempCByIndex(0);
        Serial.println(t);
                    break;
    
            case 2:
         t = WiFi.RSSI();
        Serial.println(t);
                    break;
     
          }
         
    return t;  
}




void setup() {
  Serial.begin(115200);
  delay(10);
  
  pinMode(Link_1_PIN, INPUT_PULLUP);
  last_1 = digitalRead(Link_1_PIN);

  wifi_station_set_hostname("Link");  //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] = {0x20,0x18,0x10,0x30,
                                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],
                                0x06,0x01,0x23,0x45,0x67,0x89};

   
 // char GUID[SUPLA_GUID_SIZE] = {0x10,0x45,0xE1,0x4A,0xA8,0x5C,0x11,0x58,0x8A,0xF1,0x38,0x5C,0x84,0x9F,0xFB,0xF3};
  // with GUID that you can retrieve from https://www.supla.org/arduino/get-guid



 // CHANNEL0 - DHT22
  SuplaDevice.addDHT22();                // DHT22 na GPIO04 (D2) 
  // CHANNEL1,2 DS
  SuplaDevice.addDS18B20Thermometer();// DS na GPIO2 (D4)
  SuplaDevice.addDS18B20Thermometer();  //wifi
  //CHANNEL3 - RELAY                 
  SuplaDevice.addRelay(5);       // grzalka solar  D1   
  SuplaDevice.addRelay(12);       // grzejnik lazienka  D6 
  SuplaDevice.addRelay(13);       // elektrozawor cieplej wody solar  D7 


  
  


  SuplaDevice.setName("Link");
  SuplaDevice.begin(GUID,              // Global Unique Identifier 
                    mac,               // Ethernet MAC address
                    "192.168.1.108",  // SUPLA server address
                    1,                 // Location ID 
                    "0000");               // 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);
  SuplaDevice.setTemperatureHumidityCallback(&get_temperature_and_humidity);
  httpServer.handleClient();
  
  if ( digitalRead(Link_1_PIN) != last_1 )  {
    direct_Link() ;
    last_1 = digitalRead(Link_1_PIN); 
  }
}

// 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;
  cb.get_temperature_and_humidity = &get_temperature_and_humidity;
  return cb;
}
void direct_Link() {
  
  WiFiClientSecure client2;
  Serial.print("connecting to ");
  Serial.println(host2);
  if (!client2.connect(host2, httpsPort)) {
    Serial.println("connection failed"); 
    return;
  }
  Serial.print("requesting URL: ");
  Serial.println(url);
  client2.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host2 + "\r\n" +
               "User-Agent: ESP8266\r\n" +
               "Connection: close\r\n\r\n");
  Serial.println("request sent");
  while (client2.connected()) {
    String line = client2.readStringUntil('\n');
    if (line == "\r") {
      Serial.println("headers received");
      break;
    }
  }
  String line = client2.readStringUntil('}');
  line = line + "}";
  if (line.indexOf("true") >0) {    
    Serial.println("successfull!");
  } else {
    Serial.println("failed"); 
  }
  Serial.println("reply was:");
  Serial.println("==========");
  Serial.println(line);
  Serial.println("==========");
  Serial.println("closing connection");
}
tomkowski
Posty: 372
Rejestracja: wt paź 09, 2018 7:16 pm
Lokalizacja: Orzesze

edm pisze: śr kwie 10, 2019 3:20 pm
tomkowski pisze: śr kwie 10, 2019 2:01 pm Przecież dokładnie to o co prosisz jest w pierwszym poście tego wątku.
Myślisz się. To co otrzymał @cino111 i temat z pierwszego posta to różne projekty.
Ok.. Mój błąd.
Tak na marginesie - to doskonały przykład tego co już było na forum poruszane. Mamy temat...i w tym temacie dyskusję o kilku różnych projektach choć temat na to nie wskazuje.

Dla nowych użytkowników znalezieniu tu potem czegoś to istna masakra;/
adamdd1
Posty: 18
Rejestracja: ndz cze 02, 2019 8:11 pm

wgrałem program wstawiłem swoje dane

#define Link_1_PIN 14 //D5 bistable switch in Gpio14 (D5) ---- przełącznik bistabilny w Gpio14 (D5)
const char* host2 = "svr16.supla.org"; // the url of your server or the IP --- adres URL twojego serwera lub IP
String url = "/direct/544/MTExxxxxxyQT2/turn-on"; // ----- Direct Link https://moduly.ddns.net/direct/6/GNBjYMiGZmVDZ/turn-on
const int httpsPort = 443; // https port modify if necessary
bool last_1 = false;

wszystko działa poza przyciskiem
otrzymuje taki komunikat
18:09:09.296 -> connecting to svr16.supla.org
18:09:09.466 -> connection failed
18:09:09.534 -> connecting to svr16.supla.org
18:09:09.670 -> connection failed
18:09:13.370 -> connecting to svr16.supla.org
18:09:13.539 -> connection failed
18:09:13.573 -> connecting to svr16.supla.org
18:09:13.743 -> connection failed
ODPOWIEDZ

Wróć do „Pomysły i koncepcje”