Skip to content

Instantly share code, notes, and snippets.

@reubenmiller
Created November 17, 2023 23:31
Show Gist options
  • Save reubenmiller/95011c48340d6312b27294ed48be47d4 to your computer and use it in GitHub Desktop.
Save reubenmiller/95011c48340d6312b27294ed48be47d4 to your computer and use it in GitHub Desktop.
Onboarding thin-edge.io device's to Cumulocity IoT without automatic registration enabled

Onboarding thin-edge.io to Cumulocity IoT without auto registration enabled

Part 1: Create and upload the device certificate without auto registration

  1. On the device, create the device certificate

    tedge cert create --device-id mytestdevice001
  2. Copy the public certificate from the device

    Option 1: use scp to copy it from a remote device to your machine

    scp mydevice:/etc/tedge/device-certs/tedge-certificate.pem ./mytestdevice001.pub

    Option 2: Print the public cert to console and copy paste it to a local file on your machine

    cat $(tedge config get device.cert_path)
  3. On your local machine, upload the certificate using go-c8y-cli (copied from the previous step)

    c8y devicemanagement certificates create --name mytestdevice001 --status ENABLED --file ./mytestdevice001.pub
  4. On the device again, create a simple script to retry the connection until it is successful

    file: ./tedge-connect-c8y-retry.sh

    #!/bin/sh
    set -e
    while true; do
        if tedge connect c8y; then
            echo "Connected"
            break
        fi
        echo "Connection failed. waiting 10 seconds"
        sleep 10
    done

    Note You should use a large sleep interval if you are using this in production, e.g. 600 seconds (depends on your exact use-case)

  5. Execute the script

    sudo chmod +x ./tedge-connect-c8y-retry.sh
    sudo ./tedge-connect-c8y-retry.sh
    

Part 2: Manually registering a device in Cumulocity IoT

  1. Create a local csv file with the list of devices which you want to register

    file: manual-registration.csv

    "ID","AUTH_TYPE","TYPE","NAME","com_cumulocity_model_Agent.active"
    manual_reg_001,CERTIFICATES,thin-edge.io,manual_reg_001,true
    
  2. Send the registration request to Cumulocity IoT (using go-c8y-cli)

    c8y api POST devicecontrol/bulkNewDeviceRequests --file "manual-registration.csv"
    
  3. Wait for the device to connect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment