Use hardwareserial
authorEmmanuel Lacour <elacour@easter-eggs.com>
Fri, 30 Apr 2021 21:27:01 +0000 (23:27 +0200)
committerEmmanuel Lacour <elacour@easter-eggs.com>
Fri, 30 Apr 2021 21:27:01 +0000 (23:27 +0200)
garage/garage.ino

index bb4ecaf..270d8d0 100644 (file)
@@ -4,6 +4,7 @@
 #include <Adafruit_Sensor.h>
 #include <DHT.h>
 #include <DHT_U.h>
+#include <HardwareSerial.h>
 
 #include "garage-config.h"
 
@@ -25,11 +26,14 @@ WiFiUDP Udp;
 #define DHTTYPE DHT22
 DHT_Unified dht(DHTPIN, DHTTYPE);
 
+HardwareSerial TinfoSerial(1); 
+
 TInfo tinfo;
 
 void setup() {
 
-  Serial.begin(9600);
+  Serial.begin(115200);
+  TinfoSerial.begin(9600,SERIAL_8N1, 22, 23);
   WiFi.mode(WIFI_STA);
   WiFi.begin(WIFI_SSID, WIFI_PASS);
 
@@ -43,7 +47,9 @@ void setup() {
   dht.humidity().getSensor(&sensor);
 
   tinfo.init(TINFO_MODE_STANDARD);
-  tinfo.attachNewFrame(NewTinfoFrame);
+  // tinfo.attachNewFrame(NewTinfoFrame);
+  // tinfo.attachUpdatedFrame(NewTinfoFrame);
+  tinfo.attachData(NewTinfoFrame);
 
 }
 
@@ -63,6 +69,7 @@ void loop() {
   }
 
   if ( WiFi.status() == WL_CONNECTED ) {
+      Serial.println("DEBUG");
       sensors_event_t event;
       
       dht.temperature().getEvent(&event);
@@ -77,8 +84,9 @@ void loop() {
       } else {
           sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity));
       }
-      if ( Serial.available() ) {
-        tinfo.process(Serial.read());
+      if ( TinfoSerial.available() ) {
+        Serial.println("DEBUG: process tinfo");
+        tinfo.process(TinfoSerial.read());
       }
   }
 }
@@ -91,15 +99,15 @@ void sendToInfluxDB(String measure, String key, String value) {
   Udp.endPacket();
 }
 
-void NewTinfoFrame(ValueList * me)
+void NewTinfoFrame(ValueList * me, uint8_t flags)
 {
-  Serial.print("DEBUG NewFrame");
+  Serial.println("DEBUG NewFrame");
   if ( me ) {
     while (me->next) {
       me = me->next;
-      Serial.print("DEBUG value");
+      Serial.println("DEBUG value");
       if (me->value && strlen(me->value)) {
-        Serial.print("DEBUG name: "+String(me->name)+",value: "+String(me->value));
+        Serial.println("DEBUG name: "+String(me->name)+",value: "+String(me->value));
         boolean isNumber = true;
         uint8_t c;
         char * p = me->value;
@@ -118,7 +126,7 @@ void NewTinfoFrame(ValueList * me)
         }
         // this will remove leading zero on numbers
         else {
-          Serial.print("DEBUG influx, name: "+String(me->name)+",value: "+String(atol(me->value)));
+          Serial.println("DEBUG influx, name: "+String(me->name)+",value: "+String(atol(me->value)));
           sendToInfluxDB("teleinfo,city="+city, String(me->name), String(atol(me->value)));
         }
       }