RPI Pico WIFI via ESP-01S, LWESP, FreeRTOS, and MQTT example

RPIPicoRTOSMQTT

RPI Pico WIFI via ESP-01S, LWESP, FreeRTOS, and MQTT example

Demo code for RPI Pico using ESP-01S for wifi connection over uart. With MQTT client stack to allow. Pico responds to a ping message and responds with a pong message.

Nothing clever in the code just wrapping the libraries into some C++ classes and domonstrating working example.

Hardware

  • Raspberry Pico
  • ESP-01S (1Mb) running ESP-AT 2.1

Connections:

PICO Uart0 on GPIO12 and 13

pico function ESP-01S function
G12 TX RX RX
G13 RX TX TX
3.3 3.3v 3.3 3.3v
GND GND GND GND
3.3 3.3v EN via 10k res

ESP-01S

I got very cheap pack of ESP-01S but they came with 1Mb flash. Latest version of ESP-AT, version 2.2, requires 2MB.

Fortunatly Jandrassy has built a working 2.1 firmware for 1MB. This is on github at: https://github.com/jandrassy/WiFiEspAT

To reliably upload the firmware to ESP-01S requires the RST IO0 to get pulled to zero and the released. Some further inform on how to do this at: https://blog.tiga.tech/flashing-esphome-firmware-to-esp-01s/

I used the RPI 4 to upload the firmware and the esptool.py. I had to drop frequency to 40m and change upload mode to dout in the download.config file. Then use the command esptool.py --port /dev/ttyS0 write_flash @download.config

Dependancies

C++

I could have used lwesp directly for MQTT but I wanted to move to using SSL and mutual authentication. (Both of which are not in this code, yet).

Configuration for the libraries are within the src/port folders. They are complex libraries and need proting for the Pico.

Python3

I've used the Paho python client to send a ping. See the py folder.

Cloning and build

git clone --recurse-submodules https://github.com/jondurrant/RPIPicoRTOSMQTT

main.cpp include "Credentials.env" for the Wifi AP name and passwd, MQTT Host, Port, Username and password. I've not included this file in the repo. Please create one looking something like this:

#define SID "SID"
#define PASSWD "PWD"

#define MQTTHOST "IP"
#define MQTTPORT 1883
#define MQTTUSER "jon"
#define MQTTPASSWD "PWD"

To build:

cd RPIPicoRTOSMQTT
mkdir build
cd build
cmake ..
make
make install (only work if you used my config setup in the Pico Intro course as does SWD upload of code direct from make).

MQTT Server

I'm using Mosquitto on a RPI. Followed the docker install guide at: https://docs.cedalo.com/streamsheets/2.4/installation/

Clients

Two users are setup on Mosquitto:

  • jon - test identity for the pico
  • mbp - test identity for my python ping code

Topic Structure

I've tried to condence literals a bit, nervous on memory usage.

TNG// - THING / ID, same as user name in my example TNG//LC - LC is lifecycle and annouces connection and disconnection TNG//TPC - TOPIC, for messaging to a specific thing

Example assuming you keep the pico as "jon"

  • TNG/jon/TPC/PING - ping re quest sent to jon
  • TNG/jon/TPC/PONG - pong as response to the ping

To Do List

  • Make code into a reusable library
  • Add support for a twin data structure like AWS Shadow
  • SSL Support
  • Mutual Authentication
Owner
Dr Jon Durrant
IT Professional of 25+ years. Though I have mainly worked in Architecture and Leadership, I still enjoy coding and develop as a hobby. Raspberry PI, PICO.
Dr Jon Durrant
Similar Resources

Eclipse Mosquitto - An open source MQTT broker

Mosquitto is an open source implementation of a server for version 5.0, 3.1.1, and 3.1 of the MQTT protocol. It also includes a C and C++ client library, and the mosquitto_pub and mosquitto_sub utilities for publishing and subscribing.

Jan 9, 2023

Eclipse Paho C Client Library for the MQTT Protocol

Eclipse Paho C Client Library for the MQTT Protocol This repository contains the source code for the Eclipse Paho MQTT C client library. This code bui

Apr 27, 2022

Eclipse Paho MQTT C++ Client Library

Eclipse Paho MQTT C++ Client Library This repository contains the source code for the Eclipse Paho MQTT C++ client library on memory-managed operating

Dec 30, 2022

Show pressure & temperature readings from Home Assistant/MQTT on a mini display

Show pressure & temperature readings from Home Assistant/MQTT on a mini display

home-assistant-barometer-display A mini Home Assistant display to show pressure & temperature readings (and made to look pretty with 'freeform pcb' br

Jan 4, 2022

Use an esp32 as gateway for the Eqiva Bluetooth smart lock to integrate it in Home Assistant as MQTT lock

esp32-keyble-homeassistant Use an esp32 as gateway for the Eqiva Bluetooth smart lock to integrate it in Home Assistant as MQTT lock Based on the grea

Nov 22, 2022

Google IOT MQTT Sample

This is an adaptation of Zephyr's Google Cloud IoT Core MQTT sample samples/net/cloud/google_iot_mqtt for the nRF9160-DK, using modem features to offload certificate storage, TLS and JWT calculation.

Jan 27, 2022

AirGradient Pushing to InfluxDB or MQTT

Custom AirGradient Sketch AirGradient’s sensor set up is a good base and reasonably affordable. This Arduino sketch allows you to integrate with a loc

Apr 6, 2022

16 Channel Current Meter to MQTT Gateway

 16 Channel Current Meter to MQTT Gateway

16 Channel Current Meter to MQTT Gateway This sketch runs on an ESP8266 and reads data from 16 Channel Current Measurement Module over RS485 Modbus an

Nov 11, 2022

T-Watch 2020 v1 compatible firmware providing WiFi and BLE testing tools (and also, a watch :D)

ESP-IDF template app This is a template application to be used with Espressif IoT Development Framework. Please check ESP-IDF docs for getting started

Dec 23, 2022
Comments
  • Missing MQTTPingTask

    Missing MQTTPingTask

    Compiling the project, it seems MQTTPingTask class is missing (.h/.c) :

    [ 69%] Building CXX object src/CMakeFiles/PicoMQTT.dir/main.cpp.obj
    In file included from /home/armel/Coding/RaspberryPico/RPIPicoRTOSMQTT/src/main.cpp:8:0:
    /home/armel/Coding/RaspberryPico/RPIPicoRTOSMQTT/src/MQTTRouterPing.h:14:10: fatal error: MQTTPingTask.h: No such file or directory
     #include "MQTTPingTask.h"
              ^~~~~~~~~~~~~~~~
    compilation terminated.
    make[2]: *** [src/CMakeFiles/PicoMQTT.dir/build.make:63: src/CMakeFiles/PicoMQTT.dir/main.cpp.obj] Error 1
    make[1]: *** [CMakeFiles/Makefile2:1742: src/CMakeFiles/PicoMQTT.dir/all] Error 2
    make: *** [Makefile:152: all] Error 2
    

    I've removed the class in the cmake for information

Wifi MQTT Data Logging via an esp8266 for the Ikea VINDRIKTNING PM2.5 air quality sensor
Wifi MQTT Data Logging via an esp8266 for the Ikea VINDRIKTNING PM2.5 air quality sensor

MQTT connectivity for the Ikea VINDRIKTNING This repository contains an ESP8266 firmware, which adds MQTT to the Ikea VINDRIKTNING PM2.5 air quality s

Dec 31, 2022
WiFi/MQTT Code For the ThingPulse ESPGateway
WiFi/MQTT Code For the ThingPulse ESPGateway

ESP32-Paxcounter with ThingPulse ESPGateway This project lets you run the ESP32-Paxcounter project on the ThingPulse ESPGateway. The ESPGateway has tw

Aug 13, 2022
Control Hörmann doors drives directly via MQTT from Home Assistant
Control Hörmann doors drives directly via MQTT from Home Assistant

hoermann_door Control Hörmann doors drives directly via MQTT from Home Assistant

Nov 23, 2022
ESP 32 webserver to serve a static page for wifi settings

ESP32 Settings WebServer This is a ESP32 Firmware developed in PlatformIO which consists in a HTTP server for serve static files and provides an API f

Oct 29, 2021
WiFi Attack + Recon Suite for the ESP8266 WiFi Nugget

Nugget-Invader Welcome to the Nugget Invader repository! The Invader is a WiFi attack suite developed for the WiFi Nugget, an ESP8266 based platform d

Nov 28, 2022
Bring Ethernet to the Pi Pico via SPI
Bring Ethernet to the Pi Pico via SPI

Uses lwIP in combination with the ENC28J60 SPI ethernet module to bring a TCP/IP stack to the Pi Pico!

Nov 16, 2022
An MQTT-based Virtual Wall for ESP8266 Devices and Gerber files to make the IR hat; this code and board can easily be adapted to be ANY infrared controller/remote!

Roomba-Virtual-Wall-ESP8266-MQTT An MQTT-based Virtual Wall for ESP8266 Devices I made this based off of the IRSend, IRremoteESP8266, and EspMQTTClien

Sep 20, 2021
Mongoose Embedded Web Server Library - a multi-protocol embedded networking library with TCP/UDP, HTTP, WebSocket, MQTT built-in protocols, async DNS resolver, and non-blocking API.
Mongoose Embedded Web Server Library - a multi-protocol embedded networking library with TCP/UDP, HTTP, WebSocket,  MQTT built-in protocols, async DNS resolver, and non-blocking API.

Mongoose - Embedded Web Server / Embedded Networking Library Mongoose is a networking library for C/C++. It implements event-driven non-blocking APIs

Jan 1, 2023
A portable MQTT C client for embedded systems and PCs alike.
A portable MQTT C client for embedded systems and PCs alike.

MQTT-C is an MQTT v3.1.1 client written in C. MQTT is a lightweight publisher-subscriber-based messaging protocol that is commonly used in IoT and net

Dec 29, 2022
This is a MQTT-enabled, compact weather station powered by a Wemos D1 minicontroller and built with 3D-printed parts
This is a MQTT-enabled, compact weather station powered by a Wemos D1 minicontroller and built with 3D-printed parts

This is a MQTT-enabled, compact weather station powered by a Wemos D1 minicontroller and built with 3D-printed parts. It supports OTA updates.

Feb 10, 2022