Skip to content

resulozdemir/raspberry-pi-pico-lte

Repository files navigation

Pico LTE MQTT Integration with HiveMQ Cloud

This project demonstrates the integration of the Sixfab Pico LTE board with HiveMQ Cloud to publish and subscribe to MQTT topics, enabling efficient communication between IoT devices and applications.

System Requirements

Hardware Requirements Software Requirements
  • Sixfab Pico LTE
  • Micro USB Cable
  • Thonny IDE

If you have completed all the requirements, you are ready to use HiveMQ Cloud with the Pico LTE device.

Let's get started!

Preparing Coding Environment

  1. Download the Pico LTE SDK repository to your local machine. If you have already downloaded it, skip this step.
  2. Open script "examples → hivemq → mqtt_publish.py / mqtt_subscribe.py" from the repository via Thonny IDE.
  3. If you haven't, create a config.json file in the root directory of Pico LTE device.

Create Cloud Account in HiveMQ

1. Sign Up for HiveMQ Cloud

  • Visit the HiveMQ Cloud sign-up page.
  • Choose your preferred sign-up method: GitHub, Google, LinkedIn, or email.
  • Complete the sign-up process to create your HiveMQ Cloud account.

HiveMQ Sign Up Page

HiveMQ Sign Up Page

2. Select Your HiveMQ Cloud Plan

  • Once logged in, you’ll be prompted to choose a plan.
  • For small projects or learning purposes, the Serverless plan is a great starting point with up to 100 devices and 10 GB of data traffic free.
  • Select the plan that fits your project needs and proceed with the "Get Started" option.

HiveMQ Cloud Plan Selection

3. Create Your HiveMQ Cloud Cluster

  • Click on the Create button.
  • Your cluster will be provisioned and ready to use in a few moments.

HiveMQ Create Cluster

4. Manage Your Cluster Details

  • Click on Manage Cluster to view its details.

HiveMQ Cluster Details 1

  • Here you will find your cluster URL and port, which is crucial for connecting your IoT devices.

HiveMQ Cluster Details 2

5. Access Management for Your Cluster

  • For security, you have to set up credentials that IoT devices will use to connect to your cluster.
  • Navigate to the 'Access Management' section.
  • Create new credentials, specifying a username, password, and permissions.

HiveMQ Access Management 1

6. Obtain SSL/TLS Certificates

  • Follow the steps to generate and configure your certificates.
  • Before proceeding to the certificate creation step, OpenSSL must be installed on your computer.
  • You must run the commands in the terminal.

6.1 Generate Private Key

  • First we need to create the private key by running the command.

    openssl genrsa -out user_key.pem 2048

6.2 Generate CSR (Certificate Signing Request)

  • After generating the private key, create a CSR which will be used to request an SSL certificate.

    openssl req -new -key user_key.pem -out request.csr

6.3 Generate Client Certificate

  • You will need a client certificate to authenticate with the HiveMQ broker.

    openssl x509 -req -days 365 -in request.csr -signkey user_key.pem -out client.pem

6.4 Download CA Certificate

7. Organize Certificate Files

  • Create a folder named 'cert' and upload the cacert.pem, user_key.pem, and client.pem certificates to the Raspberry Pi.

Cert File Structure

Publishing Data

  • Create the config.json file as shown below inside the Raspberry Pi and fill it with your parameters.

    {
    "hivemq": {
        "host":"[CLUSTER_URL]",
        "port": [PORT_NUMBER],
        "username": "[MQTT_USERNAME]",
        "password": "[MQTT_PASSWORD]"
        }
    }
    
  • Save this configuration and then run the example script mqtt_publish.py.

MQTT Publish Code

Subscribing Topic

  • Create the config.json file as shown below inside the Raspberry Pi and fill it with your parameters.

    {
    "hivemq": {
        "host":"[CLUSTER_URL]",
        "port": [PORT_NUMBER],
        "username": "[MQTT_USERNAME]",
        "password": "[MQTT_PASSWORD]",
        "sub_topics": [
                ["MQTT_TOPIC", QOS],
                ["MQTT_TOPIC", QOS],
                ...
            ]
        }
    }
    
  • Save this configuration and then run the example script mqtt_subscribe.py.

MQTT Subscribe Code

Files

  • config.json: Configuration file containing HiveMQ Cloud connection parameters.
  • mqtt_publish.py: Script to publish messages to MQTT topics.
  • mqtt_subscribe.py: Script to subscribe to MQTT topics and listen for incoming messages.

Conclusion

This setup enables a robust platform for developing and testing IoT applications using MQTT protocol with HiveMQ Cloud and Sixfab Pico LTE. It is suitable for anyone looking to implement IoT solutions efficiently.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published