Created
July 5, 2024 14:18
-
-
Save DimitriGilbert/0826488b03ddd3c5680e99721d33c0e6 to your computer and use it in GitHub Desktop.
TeleInfo client Linky on stationIO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Arduino.h> | |
| #include <LibTeleinfo.h> | |
| #include "./Station.h" | |
| #include "./sensors/linky.h" | |
| // use this file as main.cpp in a clone of https://github.com/DimitriGilbert/StationIO-Station | |
| // libTeleinfo https://github.com/hallard/LibTeleinfo | |
| // there is some hardware but everything is explained on the lib page | |
| NetworkInformation conInf = { | |
| "SSID", | |
| "PASS" | |
| }; | |
| // initializing station | |
| StationClass station("linky"); | |
| // ___ sensors ___ | |
| void onLinkyData(ValueList* vallnk, uint8_t flag) { | |
| LinkyOnData(&station, vallnk, flag); | |
| } | |
| TInfo tinfo; // Teleinfo object | |
| Sensor* sensors[1] = {new Linky(tinfo)}; | |
| void setup() { | |
| pinMode(LED_BUILTIN_AUX, OUTPUT); | |
| pinMode(LED_BUILTIN, OUTPUT); | |
| digitalWrite(LED_BUILTIN_AUX, LOW); | |
| station.setSerial(Serial1); | |
| station.wifi.setHostname("lnk"); | |
| station.setup(conInf); | |
| station.setupOTA(); | |
| Serial.begin(1200, SERIAL_7E1); | |
| Serial.swap(); | |
| // // Init teleinfo | |
| tinfo.init(); | |
| tinfo.attachData(onLinkyData); | |
| // setting up sensors | |
| station.setupSensors(sensors, 2); | |
| station.addEndpoint( | |
| {"/linky/data", "", "", | |
| [](BaseStation* station, AsyncWebServerRequest* request) { | |
| request->send(200, "application/json", LinkyJsonData(tinfo.getList())); | |
| }} | |
| ); | |
| digitalWrite(LED_BUILTIN_AUX, HIGH); | |
| } | |
| void loop() { | |
| station.loop(); | |
| if (Serial.available()) { | |
| char c = Serial.read(); | |
| tinfo.process(c); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment