Pomoc przy programie dla nodMCU 2x rolershuter + DHT22

Sibikk
Posts: 366
Joined: Mon Nov 07, 2016 12:42 pm
Location: Katowice

Post

Cześć, ma może ktoś gotowy przykład dla nodeMCU albo pomoże napisać.
Próbowałem ogarnąć z przykładów ale nie potrafię jakoś tego poukładać.
Chcę sterować 2 roletami z apki i z przycisków. Przekaźnik sterowany stanem niskim
Nie mam pojęcia jak dodać przyciski ogólnie ciężko mi rozryć program.

Code: Select all

/**
 * Supla.org NodeMCU WiFi minimal example
 * Author: Programistyk - Kamil Kaminski <[email protected]>
 * 
 * This example shows how to configure SuplaDevice for building for NodeMCU within Arduino IDE
 */


#include <srpc.h>
#include <log.h>
#include <eh.h>
#include <proto.h>
#include <IEEE754tools.h>
// We define our own ethernet layer
#define SUPLADEVICE_CPP
#include <SuplaDevice.h>
#include <lck.h>

#include <WiFiClient.h>
#include <ESP8266WiFiType.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiServer.h>
#include <ESP8266WiFiGeneric.h>
#include <WiFiClientSecure.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiSTA.h>
#include <WiFiUdp.h>

WiFiClient client;

// Setup Supla connection
const char* ssid     = "MyWiFiNetwork";
const char* password = "MyWiFiPassword";

void setup() {
  Serial.begin(115200);
  delay(10);

  // Replace the falowing GUID
  char GUID[SUPLA_GUID_SIZE] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  // with GUID that you can retrieve from https://www.supla.org/arduino/get-guid

  // Ethernet MAC address
  uint8_t mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

  /*
   * 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.
   */
    
  // CHANNEL 0 - RELAY
  //SuplaDevice.addRelay(44, true);           // 44 - Pin number where the relay is connected      
                                      // Call SuplaDevice.addRelay(44, true) with an extra "true" parameter 
                                      // to enable "port value inversion"
                                      // where HIGH == LOW, and LOW == HIGH   

  // CHANNEL1 - RELAY
SuplaDevice.addRelay(D1, true);           // 45 - Pin number where the relay is connected   

  // CHANNEL3 - TWO RELAYS (Roller shutter operation)
SuplaDevice.addRollerShutterRelays(D2,     // 46 - Pin number where the 1st relay is connected   
//                                     D3, true);    // 47 - Pin number where the 2nd relay is connected  

 // CHANNEL4 - TWO RELAYS (Roller shutter operation)
SuplaDevice.addRollerShutterRelays(D4,     // 46 - Pin number where the 1st relay is connected   
//                                     D5, true);    // 47 - Pin number where the 2nd relay is connected  

  // CHANNEL5 - Opening sensor (Normal Open)
SuplaDevice.addSensorNO(D6); // D6 - 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 - Opening sensor (Normal Open)
SuplaDevice.addSensorNO(D7); // D7 - Pin number where the sensor is connected


  // CHANNEL7 - DHT22 Sensor
  // SuplaDevice.addDHT11();
  // SuplaDevice.addAM2302();
 SuplaDevice.addDHT22();

  SuplaDevice.begin(GUID,              // Global Unique Identifier 
                    mac,               // Ethernet MAC address
                    "svr1.supla.org",  // SUPLA server address
                    0,                 // Location ID 
                    "");               // Location Password

}

void loop() {
  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) {

       // 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 = NULL;
          cb.get_temperature_and_humidity = NULL;
          cb.get_rgbw_value = NULL;
          cb.set_rgbw_value = NULL;
          
          return cb;
}
Image
User avatar
dawidd
Posts: 678
Joined: Tue Dec 19, 2017 12:45 pm
Been thanked: 1 time

Post

Sibikk
Posts: 366
Joined: Mon Nov 07, 2016 12:42 pm
Location: Katowice

Post

Chyba 10 razy przeczytałem tamten temat.
Image
User avatar
pzygmunt
Posts: 20302
Joined: Tue Jan 19, 2016 9:26 am
Location: Paczków
Been thanked: 59 times

Post

setRollerShutterButtons(int channel_number, int btnUpPin, int btnDownPin);

(Nie czytałem Twojeho kodu / nie mam jak teraz go przeczytać)
SUPLA.... Nareszcie w domu.
Sibikk
Posts: 366
Joined: Mon Nov 07, 2016 12:42 pm
Location: Katowice

Post

@Pzygmunt Z racji że może mi nie wystarczyć GPIO mogę ustawić tylko piny otwierające? Nie wywali błędu?
Image
User avatar
pzygmunt
Posts: 20302
Joined: Tue Jan 19, 2016 9:26 am
Location: Paczków
Been thanked: 59 times

Post

Dodaj sobie piny spoza zakresu (np >100).
Dodatkowo

Code: Select all

  SuplaDevice.setDigitalReadFuncImpl(&supla_DigitalRead);    
  SuplaDevice.setDigitalWriteFuncImpl(&suplaDigitalWrite); 
i tam ignorujesz piny spoza zakresu aby ich nie czytać ani do nich nie pisać.

Code: Select all

int supla_DigitalRead(int channelNumber, uint8_t pin) {
   if (pin > 100) {
     return 0;
   };

    return digitalRead(pin);
}
void suplaDigitalWrite(int channelNumber, uint8_t pin, uint8_t val) { 
    if (pin > 100) {
       return;
    }
   digitalWrite(pin, val);
}
SUPLA.... Nareszcie w domu.
Sibikk
Posts: 366
Joined: Mon Nov 07, 2016 12:42 pm
Location: Katowice

Post

@Pzygmunt Czy dobrze pojmuję? Na czerwono dodałem to co od siebie dopisałem.

// CHANNEL1 - TWO RELAYS (Roller shutter operation)
SuplaDevice.addRollerShutterRelays(0, 2, true);
setRollerShutterButtons(int channel_number 1, int btnUpPin 10 , int btnDownPin 102 ); // Piny dla przycisków sterujących

SuplaDevice.setDigitalReadFuncImpl(&supla_DigitalRead); 102
SuplaDevice.setDigitalWriteFuncImpl(&suplaDigitalWrite); 102

int supla_DigitalRead(int channelNumber, 1 uint8_t pin) {
if (pin > 100) {
return 0;
};

return digitalRead(pin);
}
void suplaDigitalWrite(int channelNumber, 1 uint8_t pin, uint8_t val) {
if (pin > 100) {
return;
}
digitalWrite(pin, val);
}
.
.
.
// CHANNEL2 - TWO RELAYS (Roller shutter operation)
Image

Return to “Pomoc”