ESP-IDF-example

Example of the component jef-sure/mjson v0.0.2
# ESP-IDF Example

This example shows how to use this repository as an ESP-IDF component and how
to parse static OpenWeather-style JSON payloads with `mjson_get_number()` and
`mjson_get_string()`.

The example app demonstrates:

- reading numeric values such as `$.dt` and `$.weather[0].id`
- handling `$.cod` when it is returned either as a number or as a string
- selecting a forecast entry from `$.list[]`

## Project layout

- [CMakeLists.txt](CMakeLists.txt): declares the ESP-IDF project and adds the
  repository root as an extra component directory
- [main/CMakeLists.txt](main/CMakeLists.txt): builds the example source file
- [main/simple.c](main/simple.c): example application

## Build and run

```sh
cd examples/ESP-IDF-example
idf.py set-target esp32
idf.py build flash monitor
```

## Expected log output

```text
I (...) mjson_example: current: timestamp=1716430800 sunrise=1716386400 sunset=1716438600 temp=19 weather_id=801
I (...) mjson_example: forecast: timestamp=1716443400 temp=22 weather_id=802 is_daytime=0 cod=200
```

## Notes

The repository root component enables a reduced mjson feature set for ESP-IDF:

- `MJSON_ENABLE_PRINT=0`
- `MJSON_ENABLE_BASE64=0`
- `MJSON_ENABLE_RPC=0`
- `MJSON_ENABLE_PRETTY=0`
- `MJSON_ENABLE_MERGE=0`
- `MJSON_ENABLE_NEXT=0`
- `MJSON_MAX_DEPTH=30`
- `MJSON_DYNBUF_CHUNK=256`

To create a project from this example, run:

idf.py create-project-from-example "jef-sure/mjson=0.0.2:ESP-IDF-example"

or download archive (~2.73 KB)