Josar / RandomStuff

8 stars 6 forks source link

mqtt topic like in tasmota software #1

Open lulek2007 opened 5 years ago

lulek2007 commented 5 years ago

Hello, At the beginning I would like to thank you very much for this project. He is the only one working with my accessories. I managed to build on rapberry pi 0 WH bridge with 433 sensors to mqtt and conect it to homebridge and apple homekit app.

I use digoo detectors https://www.mydigoo.com/Digoo-DG-HOSA-433MHz-Window-Door-Sensor-PIR-Detector-Wireless-Remote-Controller-External-Alert-Siren-Set-p-93.html or keriji pir 433 detectors etc.

At begining as bridge, I used https://sonoff.itead.cc/en/products/appliances/sonoff-rf-bridge-433 Sonoff 433 bridge and tasmota software.

and processed the topic from this device that looked like this

18:08:17 MQT: tele / sonoff_rf / RESULT = {"RfReceived": {"Sync": 8640, "Low": 270, "High": 850, "Data": "D3600A", "RfKey": " none "}}

in homebridge, where tele / sonoff_rf / RESULT is a topic and imprtant information is in 6 digit Date fild like "Data": "D3600A" It is hex data.

{
    "accessory": "mqttthing",
    "type": "contactSensor",
    "name": "Sensor_1",
    "url": "mqtt://192.168.4.10",
    "username": "admin",
    "password": "12345",
    "caption": "",
    "topics":
    {
        "getContactSensorState": {
            "topic": "tele/sonoff_rf/RESULT",
            "apply": "return( ( JSON.parse(message).RfReceived.Data == 'D3600A' ) ? 1 : null || ( JSON.parse(message).RfReceived.Data == 'D3600E' ) ? 0  : null);"
            },
"getStatusTampered": {
            "topic": "tele/sonoff_rf/RESULT",
            "apply": "return( ( JSON.parse(message).RfReceived.Data == 'D3600C' ) ? 1 : null );"
            },
        "getStatusLowBattery": {
            "topic": "tele/sonoff_rf/RESULT",
            "apply": "return( ( JSON.parse(message).RfReceived.Data == 'D3600D' ) ? 1 : null );"
            }
    },
        "integerValue": true,
            "logMqtt": false
    },  

I only receive dec digit in your project

Is it possible to add the conversion so that it can be published in mqtt as in tasmota software. This would make it easy for me to move to the raspberry bridge. I do not have to change the processing of all detectors to the current decimal format.

greetings Marcin Kowalik

Josar commented 5 years ago

Maybe changing the conversion to a hex string is enough.

char  valueStr[35];
sprintf(valueStr,"%A", value );

http://www.cplusplus.com/reference/cstdio/printf/

lulek2007 commented 5 years ago

Yes but not "%A" this answer -0X1.73BF800D3600AP-18

Correct is "%X" output 6 digit answer 6F5321

But how to create output string like this

MQT:  topic/RESULTS = {"RfReceived": {"Data": "D3600A"}}

I have no experience to progam this in line

sprintf(valueStr,"%X", value );

i try

sprintf(valueStr," topic/RESULTS = {"RfReceived": {"Data": "   "%X" "}}", value );

but not working

regards MK

Josar commented 5 years ago

Hi @lulek2007,

sorry for the late reply. You have to escape the " which are in the string, not the one for begin and end. And fit the size oft the array to be able to contain all the characters. Just typed this in my phone not tested, but schould be enough as example to get what to do.

char  valueStr[60];
sprintf(valueStr, "topic/RESULTS = {\"RfReceived\" : {\"Data\" : \"%X\"}}", value );
lulek2007 commented 5 years ago

Hello thank you very much for your answer I've already managed and the topic is generated correctly

I added additionally usleep (500);

            fprintf (stdout, "Received% s \ n", valueStr);
           }
         }
    
         mySwitch.resetAvailable ();
       }
     usleep (500);
    }

   // Tidy up

on my raspberry pi 0 WH because the CPU load was around 70 - 80% with the RFmqtt process running.

I have a problem with the range of the receiver, about 3m - 4m. I bought this https://www.dhgate.com/product/sovo-433-mhz-superheterodyne-rf-receiver/414959018.html and 4cm long antena for reciver

You can recommend some proven module with a better range

Regards Marcin Kowalik