jak dodam to co podał klew.krycha88 wrote: Mon Mar 29, 2021 6:19 pm zacznij od dodania jednego czujnika później dodaj kolejny itd. wtedy napisz który fragment kodu powoduje problem.
Czysty kod z BH na kanale ktrego jeszcze nie ma , BME, Wiatr jest ok. Dodajemy do kodu to :
Code: Select all
#include <supla/sensor/rain.h>
const byte interruptPin = 12;
const int interval = 500;
volatile unsigned long tiptime = millis();
double rainrate;
unsigned long curtime;
void count() {
unsigned long curtime = millis();
if ((curtime - tiptime) < interval) {
return;
}
unsigned long tipcount = curtime - tiptime;
tiptime = curtime;
rainrate = 914400.0 / tipcount;
}
class MyRain : public Supla::Sensor::Rain {
public:
double getValue() {
return rainrate*100.0;
}
};
void setup() { //
Serial.begin(9600);
// Set up our digital pin as an interrupt
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), count, FALLING);
new MyRain;
}
To działa od strzała:
Code: Select all
#include <SPI.h>
#include <SuplaDevice.h>
#include <supla/sensor/Anemometr.h>
#include <supla/sensor/BME280.h>
#include <supla/sensor/GLSBH1750.h>
#include <supla/sensor/rain.h>
#include <supla/network/esp_wifi.h>
Supla::ESPWifi wifi("X", "Y");
//#define WIND_FACTOR 2.400 // km/h
#define WIND_FACTOR 0.6666 // m/s
#define MODE_REAL 0 // The actual wind speed
#define MODE_TIME 1 // The wind speed is averaged at sampleTime or when you ask, whichever is longer
#define ANEMOMETR_PIN 12
//const byte interruptPin = 13;
//const int interval = 500;
//volatile unsigned long tiptime = millis();
//double rainrate;
//unsigned long curtime;
//
//
//void count() {
// unsigned long curtime = millis();
//
// if ((curtime - tiptime) < interval) {
// return;
// }
//
// unsigned long tipcount = curtime - tiptime;
// tiptime = curtime;
// rainrate = 914400.0 / tipcount;
//}
//
//
//class MyRain : public Supla::Sensor::Rain {
// public:
//
// double getValue() {
// return rainrate*100.0;
// }
//};
void setup() {
Serial.begin(9600);
// Set up our digital pin as an interrupt
// pinMode(interruptPin, INPUT_PULLUP);
// attachInterrupt(digitalPinToInterrupt(interruptPin), count, FALLING);
////
// new MyRain;
// Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
char GUID[SUPLA_GUID_SIZE] = {0x90, 0x7B, 0xD8, 0x9B, 0x7F, 0x9A, 0x71, 0x2E, 0xF5, 0x95, 0x36, 0xC6, 0xAE, 0x4D, 0x1A, 0x8D};
// Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {0xF0, 0xB5, 0xBC, 0xC7, 0x96, 0xA4, 0x00, 0x14, 0x93, 0x5E, 0xDD, 0x53, 0x08, 0x4A, 0xF6, 0x03};
new Supla::Sensor::Anemometr(ANEMOMETR_PIN, WIND_FACTOR, MODE_TIME );
// new Supla::Sensor::Rain(RAIN_PIN_PIN, RAIN_FACTOR, MODE_TIME );
new Supla::Sensor::BME280(0x76, 100);
new Supla::Sensor::GLSBH1750();
/*
SuplaDevice Initialization.
*/
SuplaDevice.setName("Test R@F");
SuplaDevice.begin(GUID, // Global Unique Identifier
"svr5.supla.org", // SUPLA server address
"[email protected]", // Email address used to login to Supla Cloud
AUTHKEY); // Authorization key
}
//
void loop() {
SuplaDevice.iterate();
}