Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ OSM tiles are quite large at 128kB or insane large at 512kB per tile, so psram i
You can switch provider and tile format at runtime, or set up a different default tile provider if you want.
This library can do it all and is very easy to configure and use.

### TLS validation note

This project currently uses `setInsecure()` for `WiFiClientSecure` connections, which disables certificate validation.

- Risk: Without TLS validation, responses could in theory be intercepted or altered.
This matters most if requests carry secrets (e.g. API keys).

- Practical impact: Standard OpenStreetMap tile servers do not require API keys or credentials.
In this case, the main risk is limited to someone tampering with map images.

- Benefit: Simplifies setup and supports multiple tile providers without needing to manage CA certificates.

## How to use

This library is **PlatformIO only** due to use of modern C++ features. The Arduino IDE is **not** supported.
Expand Down
27 changes: 19 additions & 8 deletions src/OpenStreetMap-esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ void OpenStreetMap::updateCache(const tileList &requiredTiles, uint8_t zoom, Til
if (!jobs.empty())
{
runJobs(jobs);
log_d("Finished %i jobs in %lu ms - %i ms/job", jobs.size(), millis() - startMS, (millis() - startMS) / jobs.size());
log_i("Finished %i jobs in %lu ms - %i ms/job", jobs.size(), millis() - startMS, (millis() - startMS) / jobs.size());
}
}

Expand Down Expand Up @@ -360,17 +360,26 @@ void OpenStreetMap::PNGDraw(PNGDRAW *pDraw)

bool OpenStreetMap::fetchTile(ReusableTileFetcher &fetcher, CachedTile &tile, uint32_t x, uint32_t y, uint8_t zoom, String &result, unsigned long timeout)
{
String url = currentProvider->urlTemplate;
url.replace("{x}", String(x));
url.replace("{y}", String(y));
url.replace("{z}", String(zoom));
if (currentProvider->requiresApiKey && strstr(url.c_str(), "{apiKey}"))
url.replace("{apiKey}", currentProvider->apiKey);
char url[256];
if (currentProvider->requiresApiKey)
{
snprintf(url, sizeof(url),
currentProvider->urlTemplate,
zoom, x, y, currentProvider->apiKey);
}
else
{
snprintf(url, sizeof(url),
currentProvider->urlTemplate,
zoom, x, y);
}

MemoryBuffer buffer = fetcher.fetchToBuffer(url, result, timeout);
if (!buffer.isAllocated())
return false;

[[maybe_unused]] const unsigned long startMS = millis();

PNG *png = getPNGCurrentCore();
const int16_t rc = png->openRAM(buffer.get(), buffer.size(), PNGDraw);
if (rc != PNG_SUCCESS)
Expand All @@ -390,10 +399,12 @@ bool OpenStreetMap::fetchTile(ReusableTileFetcher &fetcher, CachedTile &tile, ui
const int decodeResult = png->decode(0, PNG_FAST_PALETTE);
if (decodeResult != PNG_SUCCESS)
{
result = "Decoding " + url + " failed with code: " + String(decodeResult);
result = "Decoding " + String(url) + " failed with code: " + String(decodeResult);
return false;
}

log_d("decoding %s took %lu ms on core %i", url, millis() - startMS, xPortGetCoreID());

tile.x = x;
tile.y = y;
tile.z = zoom;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenStreetMap-esp32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

constexpr uint16_t OSM_BGCOLOR = lgfx::color565(32, 32, 128);
constexpr UBaseType_t OSM_TASK_PRIORITY = 1;
constexpr uint32_t OSM_TASK_STACKSIZE = 5120;
constexpr uint32_t OSM_TASK_STACKSIZE = 6144;
constexpr uint32_t OSM_JOB_QUEUE_SIZE = 50;
constexpr bool OSM_FORCE_SINGLECORE = false;
constexpr int OSM_SINGLECORE_NUMBER = 1;
Expand Down
Loading