Ok, not sure why I’m having such a hard time working through this and trying all kinds of examples from google searches, but just can’t get them to work for me. What I want to do is accept a string from an RFM69 radio of known format but of unknown number of “message:payload” pairs separated by commas like this: outTemp:68,outHumidity:55,wind:3.5 which will get posted to my MQTT server over the WiFi. Now this is data from my outdoor sensors for weather, but I want to make it generic so that if I add remote sensors for whatever I can parse the radio data “message:payload” pairs and publish it to my MQTT server. The gateway is my P1 redboard with RFM69 transceiver and my remote sensors are moteinos. So that’s the plan.
I think my mental block here is how to parse a string with an unknown number of pairs and iterate through the pairs and publish each individual pair to the MQTT server until all the pairs have been processed. My thought was to determine how many commas were in the string then the number of pairs would be #commas+1, but then how to iterate this?
The string will be this:
msgpayload = “message1:payload1,message2:payload2,…messageN:payloadN”
then publish to MQTT like this:
The MQTT client.publish function is expecting a string for the topic+message part, so that would have to be constructed, but I need that to be dynamic based on the radio packet received. The topic is stripped out at the beginning because there will only be one topic per string, that’s easy enough to strip out, but it’s the unknown number of pairs from the remote sensor location that has me vexed. Can someone give me an idea of how to do this in the most efficient way?