Dopiero zaczynam z pisaniem kodu pod suplę (Coś nieco o C i Arduino wiem).
Podłączyłem pod esp8266 na wejście analogowe rezystancyjny czujnik cieczy.
Code: Select all
auto leakDetectorResistance = new Supla::ADCDriver(A0);
auto leakDetector = new Supla::Sensor::VirtualBinary();
leakDetectorResistance->addAction(Supla::SET, leakDetector, OnGreater(500));
leakDetectorResistance->addAction(Supla::CLEAR,leakDetector,OnLess(500));
Code: Select all
#include "adc_driver.h"
using Supla::ADCDriver;
ADCDriver::ADCDriver(int gpio) {
channel.setType(SUPLA_CHANNELTYPE_THERMOMETER);
channel.setDefault(SUPLA_CHANNELFNC_THERMOMETER);
channel.setNewValue(getValue());
this->gpio = gpio;
}
int ADCDriver::getValue() {
return analogRead(gpio);
}
void ADCDriver::iterateAlways() {
if (millis() - lastReadTime > 5000) {
lastReadTime = millis();
channel.setNewValue(getValue());
}
}
To co mam na wyjściu szeregowym:
Code: Select all
21:08:15.522 -> Recv: [53 55 50 4C 41 10 08 00 00 00 32 00 00 00 10 00 00 00 1F 15 1B 65 00 00 00 00 4E BA 08 00 00 00 00 00 53 55 50 4C 41 ]
21:08:25.160 -> Channel(0) value changed to 843
21:08:25.160 -> Send: [53 55 50 4C 41 10 16 00 00 00 67 00 00 00 0E 00 00 00 00 00 00 00 00 00 4B 03 00 00 00 00 00 00 53 55 50 4C 41 ]
21:08:30.129 -> Channel(0) value changed to 907
21:08:30.162 -> Send: [53 55 50 4C 41 10 17 00 00 00 67 00 00 00 0E 00 00 00 00 00 00 00 00 00 8B 03 00 00 00 00 00 00 53 55 50 4C 41 ]
21:08:35.129 -> Channel(0) value changed to 4
21:08:35.129 -> Send: [53 55 50 4C 41 10 18 00 00 00 67 00 00 00 0E 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 53 55 50 4C 41 ]
Problemy
1. Wartość kanału 0 nijak nie zapisuje mi po stronie supli mimo, że po stronie portu szeregowego raportuje zmiany stanu
2. Wartośc kanału 1 mawet się nie zmienia mimo, że wg mnie powinna.
Co robię nie tak ?
