{"id":23390219,"url":"https://github.com/pearorchards/esp_coap_client","last_synced_at":"2026-05-16T13:07:35.354Z","repository":{"id":265934678,"uuid":"896127005","full_name":"PearOrchards/esp_coap_client","owner":"PearOrchards","description":"A simple wrapper around espressif__coap to make development significantly easier","archived":false,"fork":false,"pushed_at":"2025-01-13T15:07:50.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-21T11:51:24.661Z","etag":null,"topics":["coap-client","esp32"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PearOrchards.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-29T15:47:35.000Z","updated_at":"2025-06-10T04:08:18.000Z","dependencies_parsed_at":"2025-01-13T16:33:44.166Z","dependency_job_id":null,"html_url":"https://github.com/PearOrchards/esp_coap_client","commit_stats":null,"previous_names":["pearorchards/esp_coap_client"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/PearOrchards/esp_coap_client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PearOrchards%2Fesp_coap_client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PearOrchards%2Fesp_coap_client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PearOrchards%2Fesp_coap_client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PearOrchards%2Fesp_coap_client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PearOrchards","download_url":"https://codeload.github.com/PearOrchards/esp_coap_client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PearOrchards%2Fesp_coap_client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33103987,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coap-client","esp32"],"created_at":"2024-12-22T03:29:11.575Z","updated_at":"2026-05-16T13:07:35.307Z","avatar_url":"https://github.com/PearOrchards.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# esp_coap_client\nA simple wrapper around libcoap, designed for use with ESP32s, but should be compatible with just about everything.\n\n## Why?\nWhenever you use libcoap, there is a significant amount of overhead and code required before you can even begin to work with requests themselves.\nThis simple class intends to cut down on the amount of code required, and get you working on the fun stuff faster.\n\nI tried to emulate how Express.JS would look in C++, but to be honest it doesn't really do that. Still, I hope this helps you in some way.\n\n## Limitations\nlibcoap has a million features and I've implemented basically none of them. **This class is only designed for the simplest use-cases.** For example, there is no:\n\n- TCP Support\n- Multicast Support\n- TLS Support\n\n... which you'd expect from any feature-complete CoAP library. Remember, this isn't that. It's just a simple wrapper around libcoap to get you moving faster.\n\n## Basic Usage\n\n```c++\n#include \"esp_log.h\"\n\n#include \"coap3/coap.h\" // You still have to import the library to make your own handlers.\n#include \"CoAPClient.h\"\n\nconst static char *TAG = \"CoAP_client\";\n\n// void *p is required for FreeRTOS tasks, can be omitted otherwise\nstatic void client(void *p) {\n    CoAPClient c;\n    if (c.init()) {\n        ESP_LOGI(TAG, \"Client started successfully!\");\n    } else {\n        ESP_LOGE(TAG, \"Failed to start server.\");\n    }\n\n    // This can be done in an anonymous manner if you wish.\n    const coap_response_handler_t handler = [](coap_session_t *session, const coap_pdu_t *sent, \n                                               const coap_pdu_t *response, coap_mid_t) {\n        size_t len;\n        const uint8_t *data_buffer;\n        size_t offset;\n        size_t total;\n\n        coap_show_pdu(COAP_LOG_INFO, response);\n        if (coap_get_data_large(response, \u0026len, \u0026data_buffer, \u0026offset, \u0026total)) {\n            const char* data = reinterpret_cast\u003cconst char *\u003e(data_buffer);\n            ESP_LOGI(TAG, \"Data received! %.*s\", len, data);\n        }\n\n        coap_session_release(session);\n        return COAP_RESPONSE_OK;\n    };\n\n    c.get(\"coap://10.42.0.1/hello\", handler);\n}\n```\n\n## Installation\n\nFirst, you need to install espressif__coap into your workspace for your ESP project (if you aren't using ESPs, you can install libcoap in the regular way), which you can do with the following:\n```commandline\nidf.py add-dependency \"espressif/coap\"\n```\n(replace `idf.py` if you use IDF commands in a different way)\n\nThen, clone this repository, and move it so that your project looks something like this (other structures are also likely fine but this is the one I tested with):\n```commandline\nproject/\n |- components/\n | |- CoAPClient/\n | | |- CoAPClient.cpp\n | | |- README.md (the one you're reading!)\n | | |- ...\n | |- \u003cany other components\u003e\n |- main/\n | |- main.cpp\n | |- CMakeLists.txt\n | |- idf_component.yml\n | |- ...\n |- managed_components/\n | |- espressif__coap/\n | | |- ...\n |- CMakeLists.txt\n |- ...\n```\n\n### Updating CMakeLists.txt\n\nThe root `CMakeLists.txt` _should_ be okay left alone, though you may need to add something for CI. _An example was previously written here but, turns out, it doesn't work, so I've removed it._\n\nThe `main/CMakeLists.txt` should look like this (at the minimum):\n```cmake\nidf_component_register(SRCS main.cpp INCLUDE_DIRS \".\" REQUIRES CoAPClient)\n```\n\nAnd this repo's `CMakeLists.txt` should be left as is.\n\n### Modifying espressif__coap\nOn some systems (mine included), the `espressif__coap` library is not set up correctly. You may need to modify the library itself, and make the following adjustments:\n1. Navigate to the file located at This file is located at `managed_components/espressif__coap/port/include/coap3/coap.h`\n2. Add this line to the top of the file:\n```c++\n#ifndef _COAP_H_\n#define _COAP_H_\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n// +++++++\n#include \"coap3/libcoap.h\"\n// +++++++\n\n#if LWIP_IPV4\n#define COAP_IPV4_SUPPORT 1\n\n...\n```\n3. ... and remove the duplicate include file underneath struct definitions:\n```c++\n...\n#ifndef INET6_ADDRSTRLEN\n#define INET6_ADDRSTRLEN 40\n#endif /* INET6_ADDRSTRLEN */\n#endif /* ! LWIP_IPV6 */\n\n// --------\n#include \"coap3/libcoap.h\"\n// --------\n\n#include \"coap3/coap_forward_decls.h\"\n#include \"coap3/coap_address.h\"\n#include \"coap3/coap_async.h\"\n...\n```\n\nYou will have the issue if, during compilation, you see errors to do with missing types, such as `coap_pdu_t` or `coap_session_t`.\n\n_Note: the moved include statement MUST be inside `extern \"C\"` brackets, else you will likely get linker errors. I found this out the hard way._\n\n## Contributing and Issues\nIf you have any problems using this class, please open an issue on this repository, and I'll try get back to you as soon as possible.\n\nIf you'd like to contribute, please open a pull request. I'm happy to accept any contributions, but remember the simplicity of this \"library\". If you're looking to add a lot of features, it may be better to fork this repository and create your own.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpearorchards%2Fesp_coap_client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpearorchards%2Fesp_coap_client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpearorchards%2Fesp_coap_client/lists"}