Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect to thingsboard #3154

Open
Eching-statck opened this issue Oct 4, 2024 · 1 comment
Open

Connect to thingsboard #3154

Eching-statck opened this issue Oct 4, 2024 · 1 comment
Labels
idea ideas/opportunities/feature requests which need to be further investigated before implementation

Comments

@Eching-statck
Copy link

Can it be linked to Thingsboard Cloud?

@Eching-statck Eching-statck added the idea ideas/opportunities/feature requests which need to be further investigated before implementation label Oct 4, 2024
@Eching-statck Eching-statck changed the title connect to Thingsboard Connect to thingsboard Oct 4, 2024
@reubenmiller
Copy link
Contributor

@Eching-statck Whilst thin-edge.io does not support ThingsBoard out of the box, we're more than happy to accept PRs to add support for it. But in the meantime we took the challenge to see if we could publish some data from thin-edge.io to ThingsBoards and it only took ~30 mins or so (and I personally didn't have any experience with ThingsBoard prior to this post!)

The following instructions were used to create a manual MQTT bridge that can be used by thin-edge.io to publish data to ThingsBoard. It could be extended to also receive commands (e.g. RPCs) from ThingsBoard, but I just stopped at publishing data for now.

  1. Create a device in ThingsBoard (via the UI), and get use an access token (though certificates should also work, but it requires a bit more setup, and we're only looking at "does it work")

  2. Open a console on the device and install thin-edge.io

    wget -O - thin-edge.io/install.sh | sh -s
  3. Create an mosquitto bridge mapping, e.g. /etc/tedge/mosquitto-conf/thingsboard-bridge.conf (the file names does not matter, but the location is important!)

    Where you should set customize the following fields

    • Modify the address to suite (here I used the cloud and MQTTS as I've already added the cloud's certificate to the OS trust store using update-ca-certificates etc.)
    • Replace {{DEVICE_NAME}} with the device's name
    • Replace {{ACCESS_TOKEN}} with the device's access token
    ### Bridge
    connection edge_to_things
    address mqtt.thingsboard.cloud:8883
    bridge_capath /etc/ssl/certs
    remote_clientid {{DEVICE_NAME}}
    local_clientid ThingsBoard
    remote_username {{ACCESS_TOKEN}}
    try_private false
    start_type automatic
    cleansession true
    local_cleansession false
    notifications true
    notifications_local_only true
    notification_topic te/device/main/service/mosquitto-things-bridge/status/health
    bridge_attempt_unsubscribe false
    
    ### Topics
    
    #
    # ThingsBoard topics
    #
    # Topic mapping: things/telemetry => v1/devices/me/telemetry
    topic telemetry out 2 things/ v1/devices/me/
    
    # Topic mapping: things/attributes => v1/devices/me/attributes
    topic attributes out 2 things/ v1/devices/me/
    
    
    #
    # Also map some thin-edge.io topics to ThingsBoard topics
    #
    # Topic mapping: te/device/main///m/telemetry => v1/devices/me/telemetry
    topic "" out 2 te/device/main///m/telemetry v1/devices/me/telemetry
    
    # Topic mapping: te/device/main///m/attributes => v1/devices/me/attributes
    topic "" out 2 te/device/main///twin/attributes v1/devices/me/attributes
    
  4. Restart mosquitto

    sudo systemctl restart mosquitto
  5. Check that the ThingsBoard bridge is up

    tedge mqtt sub te/device/main/service/mosquitto-things-bridge/status/health
    

    The bridge's topic should have a value of 1 which indicates it is connected to the remote MQTT broker (ThingsBoard in this case)

    [te/device/main/service/mosquitto-things-bridge/status/health] 1
    
  6. Now publish some data to the device

    Using the things/ topic

    tedge mqtt pub things/telemetry '{"temp": 22.5}'
    tedge mqtt pub things/attributes '{"os": "debian-13"}'

    Using the thin-edge.io topic, te/

    tedge mqtt pub te/device/main///m/telemetry '{"batteryVoltage": 9.8}'
    tedge mqtt pub -r te/device/main///twin/attributes '{"os": "debian-12"}'

Some screenshots from some of the data that was posted:

image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea ideas/opportunities/feature requests which need to be further investigated before implementation
Projects
None yet
Development

No branches or pull requests

2 participants