Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website

Setting up JSON data source and point


  • Hi all,
    I am trying to set up a JSON receiver data source but cant seem to get it working. I have a GSM router with a modbus gateway that can poll modbus devices and send the data by HTTP/JSON. I have fairly limited experience with this so could anyone help with the setting up of the JSON receiver?
    0_1566343616754_4f0ca7d0-b20f-4ab1-b643-088d30ec3366-image.png Here is the router setup.
    Any help would be greatly appreciated.

    Thanks,
    Rob


  • Hi Rob,

    Can you post what a JSON message from it would look like, and what you're trying to parse out of it?

    From what I see in your screenshot, it a point may look something like,
    0_1566392557769_somethinglikethis.png

    This thread may be helpful: https://forum.infiniteautomation.com/topic/4057/how-to-set-a-value-using-http/9


  • Hi Phil, thanks for the reply.
    I have received the JSON data using a test application and it looks like this:
    POST / HTTP/1.1
    Host: 192.168.1.113:1883
    Accept: /
    Content-Length: 64
    Content-Type: application/x-www-form-urlencoded

    [{"ID":"2", "TS":"1566412285","ST":"71","VR":"[66,71,183,224]"}]POST / HTTP/1.1
    Host: 192.168.1.113:1883
    Accept: /
    Content-Length: 63
    Content-Type: application/x-www-form-urlencoded

    [{"ID":"2", "TS":"1566412286","ST":"1","VR":"[67,110,14,168]"}]

    The data i want are the 2 numerical values - 66,71,183,224 and 67,110,14,168 - Frequency and Voltage values.
    It also took me a while to figure out the data format. Its a 32Bit float but each 8 bits is in decimal. I have gotten the correct values by converting each 8 bits to binary and inputting the result into a IEE754 converter. Can this be done with the data in mango?

    As i said I have the device sending the data to the test app, running on the same pc as mango, but when i change the url to 192.168.1.113/httpds and use the listen function on the data source setup menu I don't get anything back.

    Thanks again Phil.


  • Do you have the ability to set the Content-Type header to application/json ? Otherwise you'll need to do something like catch the whole message with an HttpReceiver and parse the JSON / do the locating of points from within scripts. Only POSTs with content types containing application/json are passed to the JSON receiver data sources.

    Edit: This may not be so bad, if you'll need to do bit-banging to get the numeric value anyway (which it sounds like would be needed by that number encoding).

    It also took me a while to figure out the data format. Its a 32Bit float but each 8 bits is in decimal. I have gotten the correct values by converting each 8 bits to binary and inputting the result into a IEE754 converter. Can this be done with the data in mango?

    You can use the parseInt() function after you split the string of decimal values and pair it down. After that you'd need to bitshift and decode. Probably going to have to go through java.lang.Long (instantiate one with the lowest order byte, then bitshift and or the others into it) and java.lang.Double.longBitsToDouble() (pass this function the long from step 1)

    Maybe something like...

    //untested
    var message = JSON.parse(incoming.value);
    var regexValues = /.*(\d+),(\d+),(\d+),(\d+).*/.exec(message.VR);
    var longBits = new java.lang.Long(parseInt(regexValues[1]));
    longBits |= parseInt(regexValues[2]) <<  8;
    longBits |= parseInt(regexValues[3]) << 16;
    longBits |= parseInt(regexValues[4]) << 24;
    CONTEXT_POINTS[message.ID].set( java.lang.Double.longBitsToDouble( longBits ));

  • Thanks Phil,
    Sounds like its a bit out of my realm of knowledge but ill give it a go. Would sending the data by MQTT protocol be any better?

    0_1566414964393_dc337f99-5657-4e2f-886a-6887ec8a8a63-image.png


  • Just judging from the screenshot it looks like it would still pass the numeric value in the same format, so no it wouldn't simplify the bit-banging in a script part of things. It may simplify receiving the messages, though, since without parameter names the HTTP Receiver may have other issues to get past. It seems like that content type header is just wrong, it is not application/x-www-form-urlencoded data.