Events

:

:

Elektronik | Funk | Software

Der Technik-Blog

  • Social Media

    YouTube

    Werbung:


    New Posts


    Events

    • Keine zukünftigen Events vorhanden

    The Tech-Blog

    Ubidots TTN Webhook Integration

    Ubidots TTN Integration

    Alex @ AEQ-WEB

    Ubidots is a cloud service for the visualization of sensor data. In general, the LoRaWAN network TTN does not store any data, but only transports it to a defined cloud service such as Ubidots. The data from the sensor is then displayed there. This article is about setting up the webhook interface between TTN (The Things Stack) and Ubidots.

    What can Ubidots do?

    Ubidots collects data from IoT devices through various interfaces. This data is stored by Ubidots and displayed graphically in a dashboard. Additionally, history graphs can be created over individual values. Basically, Ubidots STEM is free for private use and for educational purposes with up to three devices.

    Requirements

    In order for Ubditos to accept data from TTN, the sensor must already be communicating with TTN. In addition, a corresponding payload decoder must be available. As an example for this project the LoRIS-Base system from ELV with the Temp-Hum1 module was used. More information can be found in this Video (German) and on the ELV Website (German).

    1. Create a TTN Plugin

    After registering with Ubditos, a new TTN (The Things Stack) plugin must be inserted under the menu item "Devices -> Data Plugin":

    2. Plugin token

    The token is a key for an interface. This ensures that only TTN can send data to Ubidots in this case. With the registration a default token is automatically created which can be used:

    Werbung:

    3. Plugin Name

    The data plugin can be assigned by a name and a description:

    4. Data Plugin

    The plugin is ready to use immediately after creation. Next, the plugin is edited to get the necessary keys for TTN:

    5. Plugin Overview with Endpoint URL

    The endpoint URL is the URL that TTN uses to transfer the user data to Ubidots. The key at the end of the URL is important, because TTN inserts it in the webhook:

    6. Auth-Token

    The Auth-Token must also be inserted into the Ubditos-Webhook at TTN. It is the default token (if not chosen otherwise):

    7. Customize the Decoder

    Ubdiots can decode the LoRaWAN payload using its own decoder. Since TTN already decodes the payload and passes it to Ubidots in JSON format, the internal decoder must be disabled. For this purpose line 37 is commented out and lines 41, 42 are commented:

    Werbung:

    Alternatively, the following decoder can be used:

    function format_payload(args){
      var ubidots_payload = {};
      // Log received data for debugging purposes:
      // console.log(JSON.stringify(args));
      // Get RSSI and SNR variables using gateways data:
      var gateways = args['uplink_message']['rx_metadata'];
      for (const i in gateways) {  
        // Get gateway EUI and name
        var gw = gateways[i];
        var gw_eui = gw['gateway_ids']['eui'];
        var gw_id = gw['gateway_ids']['gateway_id'];
        // Build RSSI and SNR variables
        ubidots_payload['rssi-' + gw_id] = {
          "value": gw['rssi'],
          "context": {
            "channel_index": gw['channel_index'],
            "channel_rssi": gw['channel_rssi'],
            "gw_eui": gw_eui,
            "gw_id": gw_id,
            "uplink_token": gw['uplink_token']
          }
        }
        ubidots_payload['snr-' + gw_id] = gw['snr'];
    
      }
      
      // Get Fcnt and Port variables:
      ubidots_payload['f_cnt'] = args['uplink_message']['f_cnt'];
      ubidots_payload['f_port'] = args['uplink_message']['f_port'];
      
      // Get uplink's timestamp
      ubidots_payload['timestamp'] = new Date(args['uplink_message']['received_at']).getTime(); 
      
      // If you're already decoding in TTS using payload formatters, 
      // then uncomment the following line to use "uplink_message.decoded_payload".
      // PROTIP: Make sure the incoming decoded payload is an Ubidots-compatible JSON (See https://ubidots.com/docs/hw/#sending-data)
       var decoded_payload = args['uplink_message']['decoded_payload'];
     
      // By default, this plugin uses "uplink_message.frm_payload" and sends it to the decoding function "decodeUplink".
      // For more vendor-specific decoders, check out https://github.com/TheThingsNetwork/lorawan-devices/tree/master/vendor
    
      // Merge decoded payload into Ubidots payload
      Object.assign(ubidots_payload, decoded_payload);
      return ubidots_payload
    }
    
    module.exports = { format_payload };
    

    8. TTN Webhook Ubidots

    After the endpoint URL and token are known, TTN sets up a webhook integration in the application:

    9. Insert Keys

    TTN now needs the plugin ID (see point 5) and the Ubidots token (see point 6). Afterwards the webhook will be created:

    10. Check Keys

    Special characters are often reformatted during copying. Therefore, both keys should be checked again:

    11. Display Sensor on Ubidots

    As soon as new data from the sensor arrives at TTN, it will be sent to Ubidots from now on. Ubditos automatically creates a new device for this purpose:

    Werbung:

    12. Display Sensor

    If you click on the new device, all available values will be displayed:

    13. Dashboard with Widgets

    A new dashboard can be created on the home page, where only the desired data is displayed. For each measured value there can be chosen different widgets:

    14. Dashboard for LoRIS Base

    After the dashboard with the widgets has been set up according to your own preferences, it may look like this:


    Info: This page was automatically translated and may contain errors
    122X122

    About the Author

    Alex, the founder of AEQ-WEB. He works for more of 10 years with different computers, microcontroller and semiconductors. In addition to hardware projects, he also develops websites, apps and software for computers.

    Top articles in this category:

    TTGO ESP32 OTTA LoRaWAN GPS Tracker

    LoRaWAN TTGO GPS Tracker

    • Video
    • DE/EN

    The second part of the LoRa GPS Tracker project is about the setup of LoRa and the registration at TTS (The Things Stack), the successor of TTN

    read more
    ESP32 LoRa Board LoRaWAN TTN ABP Connect

    LoRaWAN & TTN with ESP32

    • Video
    • DE/EN

    The ESP32 LoRa board from Heltec supports LoRa. This article is about access and data transfer to LoRaWAN & TTN

    read more

    Social Media

    YouTube

    Werbung:


    New Posts


    Events

    • Keine zukünftigen Events vorhanden