Onboarding the Raspberry Pi

Onboarding the Raspberry Pi

Now that you've created a device in the application, you can use the device's connection credentials to establish a secure link with the Raspberry Pi. Once this connection is successfully established, the Raspberry Pi will be able to send data directly to the application, allowing you to monitor and manage the data seamlessly.

Accessing the Connection Credentials

You can access the connection credentials with the following steps.
  1. Select Devices > Devices in the left pane.
  2. Click the name of the device you want the connection credentials for. For this illustration, My RPi( Device created in the previous step) is selected. This will open the device's information page.



  3. Click Actions > Connection Credentials. The connection credentials of that specific device will be displayed.


  4. Click Download Complete Registration Details to download the connection credentials as a text file.


Notes
Note: Keep the connection credentials tab open in your browser, as this will allow you to easily copy and paste the credentials.

Onboarding the Raspberry Pi

For users accessing the Raspberry Pi via GUI, open the terminal by clicking the terminal icon at the top. Then, follow these steps in the terminal to initialise the SDK:

In the terminal of users accessing via SSH, if 'root' is the username associated with your Mac or PC, you are accessing your computer. If 'root' represents the username and hostname of your Raspberry Pi, you are accessing your Raspberry Pi.

Notes
Note: The following commands are executed by typing or copying them in the terminal/command prompt and pressing return/Enter. Also, replace <username> with the username of your raspberry pi.
  1.  Go to https://github.com/zoho/zoho-iot-sdk-python in your browser.
  2. Click on the latest git in the Releases section.



  3. Note down the release version.



  4. Open the terminal of your Raspberry Pi if you are using the GUI, or SSH into the terminal of your raspberry pi if your are accessing it headless.
  5. Download the Zoho IOT Python SDK by executing the following command. Replace the x.x.x with latest version of the git you just noted. A zip file will be downloaded.

    curl -L -o zoho-iot-sdk-python.zip https://github.com/zoho/zoho-iot-sdk-python/archive/refs/tags/x.x.x.zip



  6. Unzip the downloaded file by executing the following command.

    unzip zoho-iot-sdk-python.zip



  7. Rename the extracted folder by executing the following command. Replace the x.x.x with latest version of the git you just noted.

    mv zoho-iot-sdk-python-x.x.x zoho-iot-sdk-python



  8. Open the dht_sample.py script in the extracted SDK folder  using nano with the following command.

    nano zoho-iot-sdk-python/examples/DHT_sensor/dht_sample.py



  9. Replace <username> with the username value in the connection credentials of the My RPi device created in the application. Also available in the downloaded txt file of the credentials.

    You can paste the values in the terminal with the following shortcut keys

    For Mac: command + v

    For Windows: cntrl + v

    For Linux: cntrl + shift + v

    Notes
    Note: Make sure the values are pasted inside double quotes.



  10. Replace <password> with the password/Authentication token value in the connection credentials of the My RPi device created in the application. Also available in the downloaded txt file of the credentials.



  11. After making the changes in the file, you can exit by pressing:

    For Mac: control + x

    For Windows: control + x

    For Linux: control + x

  12. Then type "y" and press return/Enter to save the file.



  13. Then press return/Enter again to confirm the file name. Make sure the file name is dht_sample.py.



    You have now successfully updated the connection credentials in the Zoho IOT SDK for the DHT22 sensor.

  14. Open the unzipped SDK folder by executing the following command.

    cd zoho-iot-sdk-python



  15. Create Virtual Python Environment by executing the following command.

    python -m venv zoho_iot


  16. Activate the virtual environment by executing the following command.

    source zoho_iot/bin/activate



    (zoho_iot) before the root user name indicates virtual environment is active. 



  17. Update the date and time of your Raspberry Pi by executing the following command. Replace YYYY with year, MM with the two-digit month number, DD with two-digit day number, HH with two-digit hour number, MM with two-digit minutes and SS with two-digit seconds.

    sudo date -s 'YYYY-MM-DD HH:MM:SS'



    Notes
    Note: This step is optional and can be skipped if the date and time on your Raspberry Pi are correct. If they are not aligned with the actual date and time, please update them, as discrepancies can cause issues when downloading the required software.

  18. Install the required packages by executing the following command.

    pip install -r requirements.txt



  19. Install the Zoho IOT Python SDK by executing the following command.

    pip install .   



  20. Navigate to the Example directory of the DHT sensor source code by executing the following command.

    cd examples/DHT_sensor/



  21. Install the DHT Sensor Example Requirements by executing the following command.

    pip install -r requirements.txt



    Notes
    Note: Installation of the packages will take few minutes
  22. Now run the DHT sensor code by executing the following command.

    python3 dht_sample.py

Once the sensors are properly connected and all the necessary requirements are installed, the device will establish a connection with the Zoho IoT application. You'll start receiving messages containing temperature and humidity data in the "My RPi" device you created within the application. The temperature and humidity readings will be published every 30 seconds.

To terminate the program/script press:
  • For Mac: Press control + C
  • For Windows: Press Ctrl + C 
 
You can restart the program at any time by executing the following commands one by one:

command 1: cd ~/zoho-iot-sdk-python-master/
command 2: source zoho_iot/bin/activate
command 3: cd examples/DHT_sensor
command 4: python3 dht_sample.py


Now that you have successfully onboarded the raspberry pi device, you can view the messages sent by the raspberry pi in the application and visualize the data.