diff options
Diffstat (limited to 'main/tollgate_client.c')
| -rw-r--r-- | main/tollgate_client.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/main/tollgate_client.c b/main/tollgate_client.c index ac8dcfe..a81d16f 100644 --- a/main/tollgate_client.c +++ b/main/tollgate_client.c | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | #include "tollgate_client.h" | 1 | #include "tollgate_client.h" |
| 2 | #include "config.h" | 2 | #include "config.h" |
| 3 | #include "nucula_wallet.h" | 3 | #include "nucula_wallet.h" |
| 4 | #include "market.h" | ||
| 4 | #include "esp_log.h" | 5 | #include "esp_log.h" |
| 5 | #include "esp_http_client.h" | 6 | #include "esp_http_client.h" |
| 6 | #include "esp_crt_bundle.h" | 7 | #include "esp_crt_bundle.h" |
| @@ -343,6 +344,19 @@ esp_err_t tollgate_client_on_sta_connected(const char *gw_ip_str) | |||
| 343 | s_state = TG_CLIENT_PAID; | 344 | s_state = TG_CLIENT_PAID; |
| 344 | 345 | ||
| 345 | ESP_LOGI(TAG, "upstream TollGate paid: %lldms allotment", (long long)allotment); | 346 | ESP_LOGI(TAG, "upstream TollGate paid: %lldms allotment", (long long)allotment); |
| 347 | |||
| 348 | const market_t *mkt = market_get(); | ||
| 349 | int cheapest = market_find_cheapest(); | ||
| 350 | if (cheapest >= 0 && mkt->entries[cheapest].valid && mkt->entries[cheapest].ssid[0] != '\0') { | ||
| 351 | uint32_t upstream_step = s_discovery.step_size_ms > 0 ? s_discovery.step_size_ms : 1; | ||
| 352 | uint32_t upstream_eff = (uint32_t)s_discovery.price_per_step * 60000 / upstream_step; | ||
| 353 | uint32_t cheap_step = mkt->entries[cheapest].step_size > 0 ? mkt->entries[cheapest].step_size : 1; | ||
| 354 | uint32_t cheap_eff = (uint32_t)mkt->entries[cheapest].price_per_step * 60000 / cheap_step; | ||
| 355 | if (cheap_eff < upstream_eff) { | ||
| 356 | ESP_LOGW(TAG, "CHEAPER TOLLGATE AVAILABLE: %s at %lu sats/min vs upstream %lu sats/min", | ||
| 357 | mkt->entries[cheapest].ssid, (unsigned long)cheap_eff, (unsigned long)upstream_eff); | ||
| 358 | } | ||
| 359 | } | ||
| 346 | return ESP_OK; | 360 | return ESP_OK; |
| 347 | } | 361 | } |
| 348 | 362 | ||