|
@@ -23,7 +23,7 @@ int serialRxCounter = 0;
|
|
|
|
|
|
void serialRxTask(void *pvParameters)
|
|
|
{
|
|
|
- const bool LOG_PRINT=true;
|
|
|
+ const bool LOG_PRINT=false;
|
|
|
|
|
|
int mode = -1; // Force a reset
|
|
|
int reset = 1;
|
|
@@ -31,7 +31,7 @@ void serialRxTask(void *pvParameters)
|
|
|
unsigned char value[200];
|
|
|
unsigned char *valP;
|
|
|
|
|
|
- printf( "serialRxTask Core:%d\n",xPortGetCoreID());
|
|
|
+ ESP_LOGI("SERIAL", "serialRxTask Core:%d\n",xPortGetCoreID());
|
|
|
|
|
|
while(1)
|
|
|
{
|
|
@@ -52,17 +52,43 @@ void serialRxTask(void *pvParameters)
|
|
|
if( c == '}' ) { // Check for end of value
|
|
|
*(valP) = '\0';
|
|
|
reset = 1;
|
|
|
- printf("\nData:%s\n",value);
|
|
|
+ if(LOG_PRINT) printf("\nData:%s\n",value);
|
|
|
char type[10];
|
|
|
- char id[12];
|
|
|
+ char id[21];
|
|
|
char data[10];
|
|
|
- const int no = sscanf((const char *)value,"%s,%s,%s",type,id,data);
|
|
|
- printf("No:%d\n",no);
|
|
|
- if( no == 1 ) printf("%s\n",type);
|
|
|
- if( no == 3 ) printf("%d %s %s %s\n",no,type,id,data);
|
|
|
+ const int no = sscanf((const char *)value,"%9[^,],%20[^,],%9s",type,id,data);
|
|
|
+ if(LOG_PRINT) printf("No:%d\n",no);
|
|
|
+ if( no == 3 ) {
|
|
|
+ if(LOG_PRINT) printf("-%s- -%s- -%s-\n",type,id,data);
|
|
|
+ if( strcmp(type,"VPP") == 0 ) {
|
|
|
+ int vpp = 0;
|
|
|
+ const int no = sscanf(data,"%d",&vpp);
|
|
|
+ if( no == 1 ) {
|
|
|
+ ESP_LOGI("SERIAL", "VPP: %d",vpp);
|
|
|
+#ifdef MQTT_ENABLED
|
|
|
+ sendMQTTMessage("/sensors/energy/waterHeater", data);
|
|
|
+#endif
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if( strcmp(type,"OWT") == 0 ) {
|
|
|
+ float t = 0.0f;
|
|
|
+ const int no = sscanf(data,"%f",&t);
|
|
|
+ if( no == 1 ) {
|
|
|
+ char js[50];
|
|
|
+ sprintf(js,"{\"id\":\"%s\",\"temp\":%s}",id,data);
|
|
|
+ ESP_LOGI("SERIAL", "%s",js);
|
|
|
+#ifdef MQTT_ENABLED
|
|
|
+ sendMQTTMessage("/sensors/energy/owTempSensor", js);
|
|
|
+#endif
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ ESP_LOGE("SERIAL", "ERROR 2");
|
|
|
+ }
|
|
|
}
|
|
|
else if( c < ',' || c > 'Z') {
|
|
|
- if(LOG_PRINT) printf("ERROR 3\n");
|
|
|
+ ESP_LOGE("SERIAL", "ERROR 3");
|
|
|
reset = 1;
|
|
|
}
|
|
|
else {
|