This topic contains 5 replies, has 4 voices, and was last updated by  Anonymous 2 years, 3 months ago. This post has been viewed 524 times

  • Author
  • #188

    Jeg får ikke TimeSeries og Table widgetene til å vise noe data. Gauge fungerer.

    Jeg sender JSON med temp, trykk og fuktighet med en Uplink Transform lik json: JSON.parse(payload.toString(“ascii”))

    Thing id: 00000486

  • #190

    Jeg fikk widgetene til å fungere hvis jeg endret Uplink Transform til “return JSON.parse(payload.toString(“ascii”))”.

    Da ble det ikke noen “sub dashboard” (husker ikke hva det sto) for thingen slik at jeg fikk verdiene i hoved-dashbordet.

  • #191
     Pontus Aurdal 

    Hi there.

    The widgets in the dashboard pull data from what’s called resources. The uplink transform allows you to modify the incoming data and create your own resources to be used by widgets.

    The variable payload contains the raw data received. You can then parse it, split it and modify it in various ways. By returning an object, each property will be made into a resource that can be used by a widget.

    Basically, what you are dong with return JSON.parse(payload.toString(“ascii”)) is to convert the incoming data (which most likely will be a bytes array) into an ASCII string, parse it as JSON and return the object.

    You can experiment with this by writing return { my_data: payload.toString("ascii"), my_uppercase_data: payload.toString("ascii").toUpperCase() }.
    After you’ve received some data, the two resources my_data and my_uppercase_data will be created and ready to be used.

    More info in the quick start guide.

    – Pontus

  • #192

    My bytes array is a string formatted as a JSON object. Is there a better way to parse it directly to JSON instead of converting it to a string first?

    Python code:

    s.send(b"{\"temp\": \""+bmeValues[0]+"\", \"pressure\": \""+bmeValues[1]+"\", \"humidity\": \""+bmeValues[2]+"\"}\n")

    • #193
       Arne Munch-Ellingsen 

      Not sure why you want to send it as a JSON object? In order to save as much battery as possible on the device side it is usually a better idea to process as little as possible and to send as little as possible (i.e. a compact binary payload). In the Uplink transformation on the Cloud Connect side you can then parse the binary payload into CC Resources. CC will than publish a corresponding JSON object on the MQTT topic associated with the device.

      If you still want to convert to JSON, maybe this is what you need:

  • #194

    @Ruben, JavaScript doesn’t have a JSON parser for byte objects. Part of the reason is that you could quickly run into encoding issues if you for example sent your JSON object with some strange encoding (like an old code page, or maybe even UTF-16). So you first have to convert it to a string while specifying the text encoding and then parse the text to JSON. In one line you can write this transform as:
    return JSON.parse(payload.toString('ascii'))

You must be logged in to reply to this topic.


Do you have any feedback? Please use the forum for technical support.


©2019 Telenor Start IoT - Privacy Policy

Log in with your credentials

Forgot your details?