Próbuje odczytać częstotliwość nadawania przez licznik wody
Nadal nie naprowadzasz, czy ten śmietnik widzisz zamiast logów?
No tak widzę ten śmietnik i próbuje to ogarnąć jakoś
Znalezione na forum Arduino
“krzaczki” w transmisji szeregowej biora sie z bledow w transmisji:
- niedopasowanie predkosci, nadajnik i odbiornik pracuja na roznych predkosciach
- niedpasowanie konfiguracji, ilosc bitow stopu czy pazystosci, ale z tym nie powinno byc problemu u ciebie, chyba ze cos zmieniales.
- bledy samej transmisji, zly kontak, slaby lub za dlugi kabel, zimene luty itd.
- uszkodzenia samego ukladu/procesora"
no o tym pisałem - jak skonfigurowałeś port szeregowy?
Zostawiłem tak jak był nic nie zmienialem chwila muszę przekopać wszystko w pc
Czyli jak?
co to kuźwa znaczy?
#include <ArduinoOTA.h>
#include "everblu_meters.h"
// Project source :
// http://www.lamaisonsimon.fr/wiki/doku.php?id=maison2:compteur_d_eau:compteur_d_eau
// Require EspMQTTClient library (by Patrick Lapointe) version 1.13.3
// Install from Arduino library manager (and its dependancies)
// https://github.com/plapointe6/EspMQTTClient/releases/tag/1.13.3
#include "EspMQTTClient.h"
// Edit "everblu_meters.h" file then change the define at the end of the file
#ifndef LED_BUILTIN
// Change this pin if needed
#define LED_BUILTIN 2
#endif
EspMQTTClient mqtt(
"x", // Your Wifi SSID
"x", // Your WiFi key
"x", // MQTT Broker server ip
"x", // Can be omitted if not needed
"x", // Can be omitted if not needed
"EverblueCyble", // Client name that uniquely identify your device
1883 // MQTT Broker server port
);
char *jsonTemplate =
"{ \
\"liters\": %d, \
\"counter\" : %d, \
\"battery\" : %d, \
\"timestamp\" : \"%s\"\
}";
int _retry = 0;
void onUpdateData()
{
struct tmeter_data meter_data;
meter_data = get_meter_data();
time_t tnow = time(nullptr);
struct tm *ptm = gmtime(&tnow);
Serial.printf("Current date (UTC) : %04d/%02d/%02d %02d:%02d:%02d - %s\n", ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, String(tnow, DEC).c_str());
char iso8601[128];
strftime(iso8601, sizeof iso8601, "%FT%TZ", gmtime(&tnow));
if (meter_data.reads_counter == 0 || meter_data.liters == 0) {
Serial.println("Unable to retrieve data from meter. Retry later...");
// Call back this function in 10 sec (in miliseconds)
if (_retry++ < 10)
mqtt.executeDelayed(1000 * 10, onUpdateData);
return;
}
digitalWrite(LED_BUILTIN, LOW); // turned on
Serial.printf("Liters : %d\nBattery (in months) : %d\nCounter : %d\n\n", meter_data.liters, meter_data.battery_left, meter_data.reads_counter);
mqtt.publish("everblu/cyble/liters", String(meter_data.liters, DEC), true);
delay(50); // Do not remove
mqtt.publish("everblu/cyble/counter", String(meter_data.reads_counter, DEC), true);
delay(50); // Do not remove
mqtt.publish("everblu/cyble/battery", String(meter_data.battery_left, DEC), true);
delay(50); // Do not remove
mqtt.publish("everblu/cyble/timestamp", iso8601, true); // timestamp since epoch in UTC
delay(50); // Do not remove
char json[512];
sprintf(json, jsonTemplate, meter_data.liters, meter_data.reads_counter, meter_data.battery_left, iso8601);
mqtt.publish("everblu/cyble/json", json, true); // send all data as a json message
}
// This function calls onUpdateData() every days at 10:00am UTC
void onScheduled()
{
time_t tnow = time(nullptr);
struct tm *ptm = gmtime(&tnow);
// At 10:00:00am UTC
if (ptm->tm_hour == 10 && ptm->tm_min == 0 && ptm->tm_sec == 0) {
// Call back in 23 hours
mqtt.executeDelayed(1000 * 60 * 60 * 23, onScheduled);
Serial.println("It is time to update data from meter :)");
// Update data
_retry = 0;
onUpdateData();
return;
}
// Every 500 ms
mqtt.executeDelayed(500, onScheduled);
}
String jsonDiscoveryDevice1(
"{ \
\"name\": \"Compteur Eau Index\", \
\"unique_id\": \"water_meter_value\",\
\"object_id\": \"water_meter_value\",\
\"icon\": \"mdi:water\",\
\"state\": \"{{ states(sensor.water_meter_value)|float / 1 }}\",\
\"unit_of_measurement\": \"L\",\
\"device_class\": \"water\",\
\"state_class\": \"total_increasing\",\
\"qos\": \"0\",\
\"state_topic\": \"everblu/cyble/liters\",\
\"force_update\": \"true\",\
\"device\" : {\
\"identifiers\" : [\
\"14071984\" ],\
\"name\": \"Compteur Eau\",\
\"model\": \"Everblu Cyble ESP8266/ESP32\",\
\"manufacturer\": \"Psykokwak\",\
\"suggested_area\": \"Home\"}\
}");
String jsonDiscoveryDevice2(
"{ \
\"name\": \"Compteur Eau Batterie\", \
\"unique_id\": \"water_meter_battery\",\
\"object_id\": \"water_meter_battery\",\
\"device_class\": \"battery\",\
\"icon\": \"mdi:battery\",\
\"unit_of_measurement\": \"%\",\
\"qos\": \"0\",\
\"state_topic\": \"everblu/cyble/battery\",\
\"value_template\": \"{{ [(value|int), 100] | min }}\",\
\"force_update\": \"true\",\
\"device\" : {\
\"identifiers\" : [\
\"14071984\" ],\
\"name\": \"Compteur Eau\",\
\"model\": \"Everblu Cyble ESP8266/ESP32\",\
\"manufacturer\": \"Psykokwak\",\
\"suggested_area\": \"Home\"}\
}");
String jsonDiscoveryDevice3(
"{ \
\"name\": \"Compteur Eau Compteur\", \
\"unique_id\": \"water_meter_counter\",\
\"object_id\": \"water_meter_counter\",\
\"icon\": \"mdi:counter\",\
\"qos\": \"0\",\
\"state_topic\": \"everblu/cyble/counter\",\
\"force_update\": \"true\",\
\"device\" : {\
\"identifiers\" : [\
\"14071984\" ],\
\"name\": \"Compteur Eau\",\
\"model\": \"Everblu Cyble ESP8266/ESP32\",\
\"manufacturer\": \"Psykokwak\",\
\"suggested_area\": \"Home\"}\
}");
String jsonDiscoveryDevice4(
"{ \
\"name\": \"Compteur Eau Timestamp\", \
\"unique_id\": \"water_meter_timestamp\",\
\"object_id\": \"water_meter_timestamp\",\
\"device_class\": \"timestamp\",\
\"icon\": \"mdi:clock\",\
\"qos\": \"0\",\
\"state_topic\": \"everblu/cyble/timestamp\",\
\"force_update\": \"true\",\
\"device\" : {\
\"identifiers\" : [\
\"14071984\" ],\
\"name\": \"Compteur Eau\",\
\"model\": \"Everblu Cyble ESP8266/ESP32\",\
\"manufacturer\": \"Psykokwak\",\
\"suggested_area\": \"Home\"}\
}");
void onConnectionEstablished()
{
Serial.println("Connected to MQTT Broker :)");
Serial.println("> Configure time from NTP server.");
configTzTime("UTC0", "pool.ntp.org");
Serial.println("> Configure Arduino OTA flash.");
ArduinoOTA.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH) {
type = "sketch";
}
else { // U_FS
type = "filesystem";
}
// NOTE: if updating FS this would be the place to unmount FS using FS.end()
Serial.println("Start updating " + type);
});
ArduinoOTA.onEnd([]() {
Serial.println("\nEnd updating.");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("%u%%\r\n", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) {
Serial.println("Auth Failed");
}
else if (error == OTA_BEGIN_ERROR) {
Serial.println("Begin Failed");
}
else if (error == OTA_CONNECT_ERROR) {
Serial.println("Connect Failed");
}
else if (error == OTA_RECEIVE_ERROR) {
Serial.println("Receive Failed");
}
else if (error == OTA_END_ERROR) {
Serial.println("End Failed");
}
});
ArduinoOTA.setHostname("EVERBLUREADER");
ArduinoOTA.begin();
mqtt.subscribe("everblu/cyble/trigger", [](const String& message) {
if (message.length() > 0) {
Serial.println("Update data from meter from MQTT trigger");
_retry = 0;
onUpdateData();
}
});
Serial.println("> Send MQTT config for HA.");
// Auto discovery
delay(50); // Do not remove
mqtt.publish("homeassistant/sensor/water_meter_value/config", jsonDiscoveryDevice1, true);
delay(50); // Do not remove
mqtt.publish("homeassistant/sensor/water_meter_battery/config", jsonDiscoveryDevice2, true);
delay(50); // Do not remove
mqtt.publish("homeassistant/sensor/water_meter_counter/config", jsonDiscoveryDevice3, true);
delay(50); // Do not remove
mqtt.publish("homeassistant/sensor/water_meter_timestamp/config", jsonDiscoveryDevice4, true);
delay(50); // Do not remove
onScheduled();
}
void setup()
{
Serial.begin(115200);
Serial.println("\n");
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH); // turned off
mqtt.setMaxPacketSize(1024);
//mqtt.enableDebuggingMessages(true);
// Use this piece of code to find the right frequency.
for (float i = 433.76f; i < 433.890f; i += 0.0005f) {
Serial.printf("Test frequency : %f\n", i);
cc1101_init(i);
struct tmeter_data meter_data;
meter_data = get_meter_data();
if (meter_data.reads_counter != 0 || meter_data.liters != 0) {
Serial.printf("\n------------------------------\nGot frequency : %f\n------------------------------\n", i);
Serial.printf("Liters : %d\nBattery (in months) : %d\nCounter : %d\n\n", meter_data.liters, meter_data.battery_left, meter_data.reads_counter);
digitalWrite(LED_BUILTIN, LOW); // turned on
while (42);
}
}
/*
cc1101_init(FREQUENCY);
// Use this piece of code to test
struct tmeter_data meter_data;
meter_data = get_meter_data();
Serial.printf("\nLiters : %d\nBattery (in months) : %d\nCounter : %d\nTime start : %d\nTime end : %d\n\n", meter_data.liters, meter_data.battery_left, meter_data.reads_counter, meter_data.time_start, meter_data.time_end);
while (42);
*/
}
void loop()
{
mqtt.loop();
ArduinoOTA.handle();
}
Nie odkomentowałeś całego kodu (nie wiem czy trzeba, ja bym odkomentował, ale gdzieś wstawiałeś filmik z YT to pewnie tam jest cała procedura), ale to nie są ustawienia seriala.
ustawione mam na 2400 baud
nie za mało?
ja bym dał minimum 19200 a pewnie optymalnie 115200?
działa 19200 dziekuje ładnie szuka
Test frequency : 433.881104
Test frequency : 433.881592
Test frequency : 433.882080
Test frequency : 433.882568
Test frequency : 433.883057
Test frequency : 433.883545
Test frequency : 433.884033
czy to znaczy ze znalazlo przy ostatniej czestotliwości ale nie podaje stanu bo licznik wysyła go raz dziennie >?
Test frequency : 433.888428
Test frequency : 433.888916
Test frequency : 433.889404
Test frequency : 433.889893
Liters : 0
Battery (in months) : 0
Counter : 0
Time start : 0
Time end : 0
Licznik nie wysyła niczego raz dziennie tylko w projekcie jest założenie odpytywania raz na dzień.
Częstotliwość na której odpowie licznik będzie OK, szczerze wątpię, że same zera to prawidłowa odpowiedź.
Tzn. to są moje wnioski po szybkim przejrzeniu tego projektu, jak już pisałem na PW, nie wczuwam się w to, bo nie ma to dla mnie żadnego zastosowania, mogłem czegoś nie doczytać.
Poranne skanowanie wykryło licznik wody nalezy skanować w godzinach roboczych od 7-15
Got frequency : 433.761475
------------------------------
Liters : 180341
Battery (in months) : 149
Counter : 16
Witam. Udalo wam sie to uruchomić ? Bo mi jakoś nie bardzo :(. Nie wiem czy w ogole modul cc mam sprawny. plytke mam wroom
źródło (electronicshub.org).
Podpiecie nastepujace do cc1101 433 MHz 1.
ESP – CC1101
GND – 1
3V3 – 2
D22 – 3
D5 – 4
D18 – 5
D23 – 6
D19 – 7
D21 – 8
W konifuracji mam
#define FREQUENCY 433.8683f
#define GDO0 22 //header 11
#define METER_YEAR 2022
#define METER_SERIAL 766706
Niestety nie moge nawiazac komunikacji, przy skanowaniu nie znajduje licznika. Jest jakis sposob aby sprawdzic czy modul w ogole jest sprawny i cos widzi?
When are you scanning for the meter? What time of the day? Which day?
Sunday at 9 a.m. and Monday between 2 - 4 p.m.
EDIT: Where i should connect the pin GDO2? I connect it to D21, but i can’t find where i can define it.
How can i check that my CC1101 working fine?
So i need edit this and set to the correct GIPO, like #define SPI_CSK 4 ?
// Change these define according to your ESP32 board
#ifdef ESP32
#define SPI_CSK SCK
#define SPI_MISO MISO
#define SPI_MOSI MOSI
#define SPI_SS SS
#endif
The year should be 2 digits, like 22.
And I suggest to read again the instructions. The code has a scanning feature as well, but you need to activate it, flash it, find the frequency and then flash it again with the correctly set frequency and disabled scanning.
At that time the meter will not answer. It has to be workdays and working hours. The Monday 2-4 PM should be good, but as I pointed out, the year was wrongly input, and it will not work with that. So again, please read again the instructions on Github.
Yee i try change it to 22 and nothing. I try today again. So where i should connect the pin GDO2 and where can i define it? In the file i only see definition to GDO0, not to GDO2.
Ok. so GDO02 is not used on this project. So today when i come back from work i try again. So i can what is the operating range? I have a water meter in a water meter well, about 30 m away.
I uncommented the code and i try find the correct frequency, but the device not find the meter. Today i will try change the manufctured date from 2022 to 22 and try again.