Error SuplaDevice.addSensorNO (SuplaNodeMCU)

francisco
Posts: 7
Joined: Fri Jun 05, 2020 10:43 pm

Post

Mój czujnik analogowy nie zwraca wartości od 0 do 1, więc mam funkcję, która decyduje, kiedy uznać ją za pustą lub pełną.
Innymi słowy, zwraca dwie wartości: wartość = 1,0 lub wartość = 0,0. W ten sposób przesyłam informacje do Supla za pośrednictwem SuplaDevice.addSensorNO, jednak aplikacja zawsze obserwuje je jako pełne. Reszta czujników działa poprawnie, więc jest to kod w ogólnych wierszach.

Code: Select all


#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";

float value;

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};

  SuplaDevice.addDHT22();
  SuplaDevice.addDS18B20Thermometer();

    //CHANNEL2  
  SuplaDevice.addRelay(13);     
 

  // CHANNEL3  
  SuplaDevice.addRelay(12); 

  //CHANNEL4
  SuplaDevice.addRelay(10);
  
  //CHANNEL5
  SuplaDevice.addRelay(9);

  //CHANNEL6
  SuplaDevice.addRelay(2);

  
 // CHANNEL7 (Normal Open)
   SuplaDevice.addSensorNO(value); 

  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();
  value=sensor();
}

// 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;
          cb.get_rgbw_value = NULL;
          cb.set_rgbw_value = NULL;
          
          return cb;
}

void sensor(){
	....
	return value;	//(value=1.0 , value=2.0)
  }

User avatar
Goral64
Posts: 3258
Joined: Fri Dec 27, 2019 6:22 pm
Location: Żerniki Wrocławskie
Has thanked: 2 times
Been thanked: 1 time

Post

No ale jak chciałeś, żeby to działało, skoro argumentem metody addSensorNO() jest pin, do którego podpięty jest sensor a nie jego wartość.
Widzimy się na Supla Offline Party Season 2026 :D

Image
User avatar
klew
Posts: 13908
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

Do metody addSensorNo podaje się nr gpio z którego sensor na czytać stan. Przekazanie tam wartości czujnika nie będzie działać
Najlepsze suple dla Twojego domu :mrgreen:
francisco
Posts: 7
Joined: Fri Jun 05, 2020 10:43 pm

Post

Prawda. Co za głupek.

Czy jest jakaś szansa na zdobycie go? Dzięki zmiennej (0,1), która nie znajduje się na wejściu analogowym, jej status można poznać w aplikacji?
francisco
Posts: 7
Joined: Fri Jun 05, 2020 10:43 pm

Post

Zmierz poziom wody w zbiorniku zgodnie z przewodnością. Odbieram dane przez wejście analogowe, ale mają trochę szumu i muszę je przefiltrować. Interesuje mnie tylko to, czy jest puste czy pełne.
User avatar
Goral64
Posts: 3258
Joined: Fri Dec 27, 2019 6:22 pm
Location: Żerniki Wrocławskie
Has thanked: 2 times
Been thanked: 1 time

Post

Ustaw sobie jakiś pin o wartości wykraczające poza dostępne dla płytki GPIO. przechwyć digitalRead() i jeśli będzie dotyczył tego pinu to wywołaj swoja metodę odczytu i zwróć 0 lub 1. Dla pozostałych wywołaj normalnie digitalRead().
Widzimy się na Supla Offline Party Season 2026 :D

Image
User avatar
Goral64
Posts: 3258
Joined: Fri Dec 27, 2019 6:22 pm
Location: Żerniki Wrocławskie
Has thanked: 2 times
Been thanked: 1 time

Post

deklaracje:

Code: Select all

#define SENSOR_PIN 40
w setup():

Code: Select all

SuplaDevice.setDigitalReadFuncImpl(&implDigitalRead);
SuplaDevice.addSensorNO(SENSOR_PIN); 
gdzieś poza setup() i loop():

Code: Select all

int readSensorPin() {
  // tutaj odczyt wejścia analogowego z czujnika
  if(warunek_dla_0) {
    return 0;
  }
  return 1;
}

int implDigitalRead(int channelNumber, uint8_t pin) {
  if(pin == SENSOR_PIN) return readSensorPin();
  return digitalRead(pin);
}
Widzimy się na Supla Offline Party Season 2026 :D

Image
krycha88
Posts: 5575
Joined: Fri Nov 16, 2018 7:25 am
Been thanked: 5 times

Post

Goral64 wrote: Sat Jun 13, 2020 2:50 pm deklaracje:

Code: Select all

#define SENSOR_PIN 40
w setup():

Code: Select all

SuplaDevice.setDigitalReadFuncImpl(&implDigitalRead);
SuplaDevice.addSensorNO(SENSOR_PIN); 
gdzieś poza setup() i loop():

Code: Select all

int readSensorPin() {
  // tutaj odczyt wejścia analogowego z czujnika
  if(warunek_dla_0) {
    return 0;
  }
  return 1;
}

int implDigitalRead(int channelNumber, uint8_t pin) {
  if(pin == SENSOR_PIN) return readSensorPin();
  return digitalRead(pin);
}
Myślałem, że pracujesz już na nowej bibliotece 🙂
https://gui-generic-builder.supla.io/
User avatar
Goral64
Posts: 3258
Joined: Fri Dec 27, 2019 6:22 pm
Location: Żerniki Wrocławskie
Has thanked: 2 times
Been thanked: 1 time

Post

krycha88 wrote: Sat Jun 13, 2020 3:01 pm Myślałem, że pracujesz już na nowej bibliotece 🙂
Ja tak, ale francisco nie :)
Widzimy się na Supla Offline Party Season 2026 :D

Image
francisco
Posts: 7
Joined: Fri Jun 05, 2020 10:43 pm

Post

Pracuje! :D :D
Spojrzę na nową wersję

Return to “Pomoc”