An application running on Raspberry Pi 5 using the FreeRTOS POSIX/Linux Simulator. The program periodically fetches weather data from the OpenWeatherMap API and publishes it to an MQTT broker.
The application consists of two FreeRTOS tasks and one software timer.
- Fires every 2 hours (default:
PERIOD_ASK = 7 200 000 ms) - Wakes up the
vWeatherTasktask viaxTaskNotifyGive
- Waits for a notification from the timer
- Iterates over a grid of measurement points defined in the
latitudes[]andlongitudes[]arrays - For each point, performs an HTTP request to the OpenWeatherMap API using
curland retrieves a JSON response - Parses the response using the cJSON library, extracting:
coord.lon/coord.lat– coordinatesmain.temp– temperature in Celsiuswind.speed– wind speed in m/sweather[0].description– weather description
- Builds a JSON array from all measurement points and sends it to
jsonQueue - Signals
vSendDatathat data is ready viadataReadySem
- Waits on the
dataReadySemsemaphore - Receives the JSON array from the queue
- Serializes the JSON to a string and calls
mosquitto_pubviasystem() - Publishes the data to topic
projekt/pogoda/C1on the configured broker
.
├── main_blinky.c # Main application logic (tasks, timer)
├── main.c # Entry point – calls main_blinky()
├── cJSON/
│ ├── cJSON.c # JSON parsing library
│ └── cJSON.h
├── FreeRTOSConfig.h # FreeRTOS configuration
├── CMakeLists.txt # CMake build system
├── Makefile # Alternative build file
└── README.md
- Raspberry Pi 5 running Linux (Raspberry Pi OS or Ubuntu)
- FreeRTOS POSIX/Linux Simulator
curl– for fetching data from OpenWeatherMapmosquitto-clients– for publishing via MQTT (mosquitto_pub)- An API key from openweathermap.org
- A running MQTT broker accessible on the network (e.g. Mosquitto)
sudo apt update
sudo apt install curl mosquitto-clients build-essential cmakegit clone <REPOSITORY_URL>
cd <repository-directory>In main_blinky.c, set the following defines:
#define MQTT_HOST "your_broker_ip"
#define MQTT_PORT 1883
#define MQTT_TOPIC "projekt/pogoda/C1"
#define OWM_API_KEY "your_api_key"Optionally, adjust the measurement points in the latitudes[] and longitudes[] arrays.
mkdir build && cd build
cmake ..
makeOr using the Makefile:
make./FreeRTOS_WeatherData published to the topic is a JSON array:
[
{
"lon": 14.1,
"lat": 49.0,
"temp": 18.45,
"speed": 3.2,
"description": "light clouds"
}
]| Mechanism | Usage |
|---|---|
xTimerCreate |
Periodic wake-up every 2 hours |
xTaskNotifyGive |
Timer notifies vWeatherTask |
xSemaphoreCreateMutex (czekaj_na_dane) |
Protects the data acquisition critical section |
xSemaphoreCreateBinary (dataReadySem) |
Signals that data is ready to send |
xQueueCreate (jsonQueue) |
Passes the JSON pointer between tasks |
This project uses the FreeRTOS Simulator for Linux, which allows FreeRTOS code to run natively on a Linux system without dedicated embedded hardware. Each FreeRTOS task is mapped to a POSIX thread (pthread), so queues, semaphores, and timers all work as they would on a microcontroller. This makes Raspberry Pi 5 a convenient development and deployment platform.
More information: https://github.com/FreeRTOS/FreeRTOS-Simulator-for-Linux