Czujniki w bibliotece SuplaDevice
-
- Posts: 2299
- Joined: Thu Nov 23, 2017 11:33 pm
- Location: Warszawa
Jak można ograniczyć listę funkcji czujnika binarnego?
https://www.facebook.com/groups/supladiy/
-
- Posts: 10022
- Joined: Thu Jun 27, 2019 12:16 pm
- Location: Wrocław
W zasadzie robi się to tak:
Code: Select all
sensor->getChannel()->setFuncList(FUNKCJA_1 | FUNKCJA_2 | ...);
Więc chyba się nie da tym sposobem ograniczyć listy wyświetlanych funkcji.
Natomiast powinno dać się ustawić domyślną funkcję - wtedy od razu po zarejestrowaniu danego kanału przez urządzenie, będzie ono posiadało skonfigurowaną funkcję i pojawi się w apce na telefonie.
Ustawia się to tak:
Code: Select all
sensor->getChannel()->setDefault(SUPLA_CHANNELFNC_....);
Po nazwach musisz odgadnąć, które dotyczą sensora binarnego.
-
- Posts: 2299
- Joined: Thu Nov 23, 2017 11:33 pm
- Location: Warszawa
Rozumiem, że podobnie dla przekaźnika? Na tą chwilę mam:klew wrote: Tue Feb 02, 2021 11:17 pm W zasadzie robi się to tak:Code: Select all
sensor->getChannel()->setFuncList(FUNKCJA_1 | FUNKCJA_2 | ...);
Code: Select all
new Supla::Control::Relay(4, true, SUPLA_BIT_FUNC_CONTROLLINGTHEGATEWAYLOCK | ... ) ;
No właśnie widziałem, szkoda.. Przydało by się dodać taką możliwość.klew wrote: Tue Feb 02, 2021 11:17 pm Z tym że dla sensorów binarnych nie ma żadnych zdefiniowanych SUPLA_BIT_FUNC_.
Więc chyba się nie da tym sposobem ograniczyć listy wyświetlanych funkcji.
Przyda się, dziękiklew wrote: Tue Feb 02, 2021 11:17 pm Natomiast powinno dać się ustawić domyślną funkcję - wtedy od razu po zarejestrowaniu danego kanału przez urządzenie, będzie ono posiadało skonfigurowaną funkcję i pojawi się w apce na telefonie.
Ustawia się to tak:Code: Select all
sensor->getChannel()->setDefault(SUPLA_CHANNELFNC_....);
https://www.facebook.com/groups/supladiy/
-
- Posts: 10022
- Joined: Thu Jun 27, 2019 12:16 pm
- Location: Wrocław
To już wymaga raczej zmian po stronie serwera i clouda.
@pzygmunt, co myślisz?
-
- Posts: 19340
- Joined: Tue Jan 19, 2016 9:26 am
- Location: Paczków
Na chwile obecna nie ma parametru, który może ograniczyć listę funkcji dla czujników.
-
- Posts: 2849
- Joined: Mon Jan 07, 2019 7:51 pm
- Location: Rybnik
Taka drobna "literówka".
Powinno być MAX31855
https://github.com/ermaya/arduino/blob/ ... le.cpp#L46
Powinno być MAX31855
https://github.com/ermaya/arduino/blob/ ... le.cpp#L46
-
- Posts: 1483
- Joined: Wed Jun 27, 2018 5:48 pm
- Location: El Saucejo - Sevilla
it's just a comment but you're rightPatryk wrote: Thu Feb 11, 2021 2:34 pm Taka drobna "literówka".
Powinno być MAX31855
https://github.com/ermaya/arduino/blob/ ... le.cpp#L46
corrected
-
- Posts: 2352
- Joined: Sun Sep 03, 2017 9:13 am
- Location: Koszalin
a jak dodać czujnik deszczu ?
jak określić pin w esp?
Code: Select all
new Supla::Sensor::Rain ???....???
jak coś nie działa to włącz zasilanie.....
-
- Posts: 10022
- Joined: Thu Jun 27, 2019 12:16 pm
- Location: Wrocław
To jest tylko klasa bazowa bez implementacji konkretnego urządzenia.QLQ wrote: Sat Mar 27, 2021 7:33 pm a jak dodać czujnik deszczu ?jak określić pin w esp?Code: Select all
new Supla::Sensor::Rain ???....???
Czujnik deszczu i tak lepiej zrobić na liczniku impulsów, tylko tam jest problem ze często wymaga to ułamkowego przelicznika, którego nie wspiera serwer.
-
- Posts: 2352
- Joined: Sun Sep 03, 2017 9:13 am
- Location: Koszalin
Przecież jest osobny kanał do deszczu. I na tym kanale chce ten czujnik. Podpowiesz proszę coś więcej?klew wrote: Sat Mar 27, 2021 8:58 pmTo jest tylko klasa bazowa bez implementacji konkretnego urządzenia.QLQ wrote: Sat Mar 27, 2021 7:33 pm a jak dodać czujnik deszczu ?jak określić pin w esp?Code: Select all
new Supla::Sensor::Rain ???....???
Czujnik deszczu i tak lepiej zrobić na liczniku impulsów, tylko tam jest problem ze często wymaga to ułamkowego przelicznika, którego nie wspiera serwer.
Kod deszczomierza:
Code: Select all
/**
Supla.org NodeMCU WiFi minimal example
Author: Programistyk - Kamil Kaminski <kamil@programistyk.pl>
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>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
#define OLED_RESET 0
Adafruit_SSD1306 display(OLED_RESET); // GPIO5 - SCL , GPIO4 -SDA
const byte interruptPin = 12;
const int interval = 500;
volatile unsigned long tiptime = millis();
double rainrate;
unsigned long curtime;
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO32_GLCD_HEIGHT 32
#define LOGO32_GLCD_WIDTH 32
static const unsigned char PROGMEM temp_glcd_bmp[] =
{ // temp_home
0x00, 0x03, 0xc0, 0x00, 0x00, 0x04, 0x20, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x50, 0x00,
0x00, 0x08, 0x50, 0x00, 0x00, 0x08, 0x50, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x09, 0x50, 0x00,
0x00, 0x08, 0xd0, 0x00, 0x00, 0x0b, 0x10, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00,
0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00,
0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00,
0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x0b, 0xd0, 0x00, 0x00, 0x17, 0xe8, 0x00,
0x00, 0x2f, 0xf4, 0x00, 0x00, 0x2f, 0x94, 0x00, 0x00, 0x2f, 0xb4, 0x00, 0x00, 0x2f, 0xf4, 0x00,
0x00, 0x07, 0xe0, 0x00, 0x00, 0x13, 0xc8, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x03, 0xc0, 0x00
};
static const unsigned char PROGMEM waga_glcd_bmp[] =
{
0x00,0x00,0x80,0x00, // ········▌·······
0x00,0x01,0xC0,0x00, // ·······▐█·······
0x00,0x01,0xC0,0x00, // ·······▐█·······
0x00,0x01,0xC0,0x00, // ·······▐█·······
0x3F,0xFF,0xFF,0xFC, // ·██████████████·
0x3F,0xFF,0xFF,0xFE, // ·██████████████▌
0x3F,0xFF,0xFF,0xFE, // ·██████████████▌
0x07,0x81,0xC0,0xF0, // ··▐█▌··▐█···██··
0x07,0x81,0x80,0xF0, // ··▐█▌··▐▌···██··
0x0F,0xC1,0xC1,0xF8, // ··███··▐█··▐██▌·
0x1C,0xC1,0xC1,0x98, // ·▐█·█··▐█··▐▌▐▌·
0x18,0xE1,0xC3,0x8C, // ·▐▌·█▌·▐█··█▌·█·
0x38,0x61,0xC3,0x0E, // ·█▌·▐▌·▐█··█··█▌
0x30,0x71,0xC7,0x06, // ·█··▐█·▐█·▐█··▐▌
0xFF,0xF9,0xCF,0xFF, // ██████▌▐█·██████
0xFF,0xF9,0xCF,0xFF, // ██████▌▐█·██████
0xFF,0xF9,0xCF,0xFF, // ██████▌▐█·██████
0x7F,0xF9,0xCF,0xFF, // ▐█████▌▐█·██████
0x3F,0xF1,0xC7,0xFE, // ·█████·▐█·▐████▌
0x3F,0xE1,0xC3,0xFE, // ·████▌·▐█··████▌
0x0F,0xC1,0xC1,0xF8, // ··███··▐█··▐██▌·
0x00,0x01,0xC0,0x00, // ·······▐█·······
0x00,0x01,0xC0,0x00, // ·······▐█·······
0x00,0x01,0xC0,0x00, // ·······▐█·······
0x00,0x01,0xC0,0x00, // ·······▐█·······
0x00,0x01,0x80,0x00, // ·······▐▌·······
0x00,0x1F,0xFC,0x00, // ·····▐█████·····
0x00,0x3F,0xFE,0x00, // ·····██████▌····
0x00,0x3F,0xFE,0x00, // ·····██████▌····
0x00,0x3F,0xFE,0x00, // ·····██████▌····
0x00,0x1F,0xFC,0x00, // ·····▐█████·····
0x00,0x00,0x00,0x00 // ················
};
static const unsigned char PROGMEM logo32_glcd_bmp[] =
{
// 'logo SUPLA'
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00,
0x0e, 0x0e, 0x00, 0x00, 0x0c, 0x06, 0x00, 0x00, 0x1c, 0x03, 0x00, 0x00, 0x1c, 0x03, 0x00, 0x00,
0x1c, 0x03, 0x00, 0x00, 0x0c, 0x07, 0x00, 0x00, 0x0e, 0x0f, 0x80, 0x00, 0x07, 0xfc, 0xe0, 0x00,
0x03, 0xf8, 0x30, 0x00, 0x00, 0xf0, 0x0d, 0xe0, 0x00, 0x10, 0x07, 0x30, 0x00, 0x18, 0x02, 0x10,
0x00, 0x18, 0x06, 0x18, 0x00, 0x08, 0x02, 0x10, 0x00, 0x08, 0x03, 0xf0, 0x00, 0x0c, 0x07, 0xc0,
0x00, 0x04, 0x0c, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x04, 0x10, 0x00, 0x00, 0x00, 0x20, 0x00,
0x00, 0x03, 0xc0, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x00, 0x0c, 0x20, 0x00,
0x00, 0x04, 0x40, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static const unsigned char PROGMEM ASL_glcd_bmp[] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
0x00, 0x00, 0x60, 0x00, 0x00, 0x08, 0x21, 0x00, 0x00, 0x0c, 0x03, 0x00, 0x00, 0x00, 0x62, 0x00,
0x00, 0x1f, 0xf8, 0x00, 0x00, 0x3f, 0x0c, 0x00, 0x00, 0x61, 0x84, 0x00, 0x00, 0xc0, 0xc4, 0xe0,
0x01, 0xc0, 0xf4, 0x00, 0x03, 0x00, 0x1c, 0x00, 0x06, 0x00, 0x0c, 0x00, 0x06, 0x00, 0x0c, 0x00,
0x06, 0x10, 0xcd, 0x00, 0x03, 0x10, 0x99, 0x00, 0x01, 0x84, 0x30, 0x00, 0x00, 0x25, 0x00, 0x00,
0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
char* Message[] = {"This is string 1",
"Already initialized",
"Cb not assigned",
"Invalid GUID",
"Unknown server address",
"Unknow location ID",
"Initialized",
"Channel limit exceeded",
"Rozlaczony",
"Rejstracja w toku",
"Iterate fail",
"Protocol version error",
"Bad credentials",
"Temporarily unawaliable",
"Location conflict",
"Channel conflict",
"Polaczony i gotowy",
"Device is diasbled",
"Location is disabled",
"Device limit execeeded"
};
#if (SSD1306_LCDHEIGHT != 64)
//#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
// ***** logowanie WiFi ********************************************************************************
WiFiClient client;
// Setup Supla connection
const char* ssid = "sssdF";
const char* password = "kcxcsd9";
char str[10];
char StatCommStr[25];
int StatCommInt;
byte Icon;
byte FiveSek;
//*****************************OPADY_DESZCZ*******************************************
double get_rain(int channelNumber, double t) {
//double t = -275;
t = rainrate*100;
return t;
}
//**********************************WYLICZ OPADY****************************************
void count() {
float de;
// Grab the current ms count for common calculations
unsigned long curtime = millis();
// Make sure we don't record bounces
if ((curtime - tiptime) < interval) {
return;
}
// How long since the last tip?
unsigned long tipcount = curtime - tiptime;
tiptime = curtime;
// Calculate mm/hr from period between cup tips
rainrate = 914400.0 / tipcount;
Serial.print("Cup tip: ");
Serial.print(tipcount);
Serial.println("ms");
Serial.print("Opady deszczu: ");
Serial.print(rainrate/10);
Serial.println("l/m2");
Serial.println("mm/h");
}
//**************************#########################################################
void timer0_ISR (void) {
FiveSek++;
if (FiveSek==2) {
FiveSek=0;
Icon++;
if (Icon==3) Icon=1;
}
timer0_write(ESP.getCycleCount() + 80000000L); // 80MHz == 1sec
}
//// ******* Funkcja główna *********************************************************************************
void setup() {
Serial.begin(9600);
// Set up our digital pin as an interrupt
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), count, FALLING);
noInterrupts();
timer0_isr_init();
timer0_attachInterrupt(timer0_ISR);
timer0_write(ESP.getCycleCount() + 80000000L); // 80MHz == 1sec
interrupts();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x64)
Icon = 0;
// Clear the buffer.
display.clearDisplay();
// text display tests
display.setTextSize(3);
display.setTextColor(WHITE);
display.setRotation(2);
display.setCursor(30, 25);
display.print("SUPLA");
drawbitmap(logo32_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH);
display.display();
// Replace the falowing GUID
char GUID[SUPLA_GUID_SIZE] = {0xF0,0xE2,0xA7,0x5A,0xF6,0xDF,0xE8,0x24,0xA6,0xAE,0x36,0x2A,0x8F,0x11,0xD7,0x18};
// 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.
*/
// CHANNEL0
SuplaDevice.addRainSensor(); //deszcz czujnik
SuplaDevice.setName("R@F_Deszcz");
SuplaDevice.setStatusFuncImpl(&status_func);
SuplaDevice.begin(GUID, // Global Unique Identifier
mac, // Ethernet MAC address
"svr5.supla.org", // SUPLA server address
854645, // Location ID
"6575"); // Location Password
}
// ***********************************************************************************************************
void loop() {
SuplaDevice.iterate();
DisplayTemp();
}
// **** Obsługa OLED ****************************************************************************************************
void DisplayTemp() {
display.clearDisplay();
display.setTextSize(3);
display.setTextColor(WHITE);
display.setRotation(2);
display.setCursor(45, 25);
switch (Icon) {
case 1:
display.setTextSize(4);
display.setCursor(30, 20 );
// display.print(waga, 0);
display.print("kg" );
drawbitmap(waga_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH);
break;
case 2:
display.setTextSize(4);
display.setCursor(30, 20 );
// display.print(waga, 0);
display.print("kg" );
drawbitmap(waga_glcd_bmp, LOGO32_GLCD_HEIGHT, LOGO32_GLCD_WIDTH);
break;
//---------------------
};
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 55);
display.print(Message[StatCommInt - 1]);
display.display();
display.display();
}; //DisplayTemp
void drawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
uint8_t icons[NUMFLAKES][3];
display.drawBitmap(0, 0, bitmap, w, h, WHITE);
} //drawbitmap
// 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_rain = get_rain;
cb.get_temperature_and_humidity = NULL;
cb.get_pressure = NULL;
cb.get_temperature = NULL;
cb.get_rgbw_value = NULL;
cb.set_rgbw_value = NULL;
cb.get_distance= NULL;
return cb;
}
void status_func(int status, const char *msg) {
Serial.print("Status : ");
Serial.print(status);
StatCommInt = status;
Serial.print(" - ");
Serial.println(Message[StatCommInt - 1]);
display.fillRect(0, 55, 128, 65, BLACK);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setRotation(2);
display.setCursor(0, 55);
display.print(Message[StatCommInt - 1]);
display.display();
}
jak coś nie działa to włącz zasilanie.....