Browse Source

Corrected the ESIC receiver.

Thomas Chef 5 years ago
parent
commit
8946e01e9c
3 changed files with 55 additions and 16 deletions
  1. 40 9
      main/Sensors/esic.c
  2. 1 1
      main/Sensors/esic.h
  3. 14 6
      main/receiver.c

+ 40 - 9
main/Sensors/esic.c

@@ -59,6 +59,23 @@
     hc, cc = house code and channel code
     rh, t  = relative humidity, temperature
     p      = parity bit 1111111111111110
+
+
+	This interpretation is from: https://github.com/merbanan/rtl_433/blob/master/src/devices/wt450.c
+
+	   1100 0001 | 0011 0011 | 1000 0011 | 1011 0011 | 0001
+	   xxxx ssss | ccxx bhhh | hhhh tttt | tttt tttt | sseo
+
+	- x: constant
+	- s: House code
+	- c: Channel
+	- b: battery low indicator (0=>OK, 1=>LOW)
+	- h: Humidity
+	- t: Temperature, 12 bit, offset 50, scale 16
+	- s: sequence number of message repeat
+	- e: parity of all even bits
+	- o: parity of all odd bits
+
 **********************************************************************************
 */
 
@@ -208,6 +225,7 @@ RES:    0000 0001 00 110 0000000 000000000000000 0  = 00000001001100000000000000
 				}
 				// A correct code has been received
 				//printf("Code received: %llu on row:%d\n",(code&0xFFFFFFFF),row_no);
+				temp3_x_data &= 0xFFFFFFF0;	// Remove sequence and parity bits in lowest nibble
 				return 1;
 				
 			}
@@ -234,15 +252,28 @@ static int temp3decode (unsigned int inWidth) {
 
 int64_t nextPulseESICSensor(uint32_t width) {
   
-  volatile static int result;
+  	static int64_t previous_data = 0;
+	static uint32_t old_time=0;
+	static uint32_t now;
+	int64_t retVal = -1;
   
-  if( width > 0 ) {
-    if( temp3_x_data == 0 ) {
-      
-      result = temp3decode(width);
-
-    }
-  }
+	if( width > 0 ) {
+		if( temp3_x_data == 0 ) {
+			temp3decode(width);
+		}
+	}
   
-  return (temp3_x_data > 0);
+	if( temp3_x_data > 0 ) {
+		now = millis();
+
+		if( temp3_x_data != previous_data || (now > (old_time+1000)) ) {
+            previous_data = temp3_x_data;
+            retVal = temp3_x_data;
+            blinkTheLED();
+		}
+		old_time = now;
+		ESIC_ResetDecoder();
+	}
+	
+	return retVal;
 }

+ 1 - 1
main/Sensors/esic.h

@@ -4,7 +4,7 @@
 #include <stdbool.h>
 #include <stdint.h>
 
-void ESIC_ResetDecoder ();
+void ESIC_ResetDecoder();
 
 int64_t nextPulseESICSensor(uint32_t width);
 

+ 14 - 6
main/receiver.c

@@ -134,13 +134,20 @@ void receiverTask(void *pvParameter)
             }
 
             // ESIC (Fridge / Freezer Sensors)
-            if( nextPulseESICSensor(width) ) {
+            data = nextPulseESICSensor(width);
+            if( data != -1 ) {
 
-                ESP_LOGE("RX", "NO WAY");
-     
-                
-                    ESIC_ResetDecoder();          
-                    blinkTheLED();      
+                int32_t value	   = (data & 0xFFFE) >> 1;
+		                value	   = (value - 6400) * 10 / 128;
+
+                int32_t id         = (data>>12) & 0x007;
+
+                ESP_LOGI("RX", "ESIC:   <TE%08llX> %u               %4.1f",data,id, (float)value/10);
+
+                sprintf(dataStr,"<TE%08llX>\n",data);
+#ifdef WIFI_ENABLED
+                sendUDPMessage(dataStr);
+#endif
             }
         }
     }
@@ -152,6 +159,7 @@ void initReceiver() {
     Oregon_ResetDecoder();
     ClasO_ResetDecoder();
     ProovesmartSensor_ResetDecoder();
+    ESIC_ResetDecoder();
             
     ESP_LOGI("RX", "Receiver has been initialized.");