i want to use the BLYNK App for visualization of the incoming and decoded payload.
HTTP integration works well by using the GET method in TTN
“http://139.59.206.133/<BLYNK_TOKEN>/update/v0?value=12345” (in this case the value “12345” is pushed to the BLYNK App on PIN V0)
Is it possible to insert value from the decoded payload (e.g. “decoded.myDecodedValue”)?
something like that: “http://139.59.206.133/<BLYNK_TOKEN>/update/v0?value=decoded.myDecodedValue”
No, that would need an intermediate server (which could then also subscribe to MQTT directly, without using the HTTP Integration). See HTTP Integration: pass only payload_fields.
here is some example code which runs on a server (e.g. ESP8266) and forwards the incoming data (JSON from HTTP integration from TTN servers) and sends it to your blynk server.
tested successfully and using it for month already.
in the setup:
server.on("/<specified in the http integration>/", HTTP_POST, send_ttn_to_blynk);
void send_ttn_to_blynk() {
const size_t capacity = JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(1) + JSON_OBJECT_SIZE(6) + 2 * JSON_OBJECT_SIZE(10) + 610;
DynamicJsonDocument doc(capacity);
String json_string = server.arg("plain");
deserializeJson(doc, json_string);
String payload_raw = doc["payload_raw"];
char payload_raw_char[payload_raw.length() + 1];
payload_raw.toCharArray(payload_raw_char, payload_raw.length() + 1);
int decodedLen = base64_dec_len(payload_raw_char, sizeof(payload_raw_char));
char decoded[decodedLen];
base64_decode(decoded, payload_raw_char, sizeof(payload_raw_char));
String decoded_data_string = String(decoded);
// data in this example is battery and position of a gps tracker sending its data via ttn
int first_comma = decoded_data_string.indexOf(",");
int second_comma = decoded_data_string.indexOf(",", first_comma + 1);
int third_comma = decoded_data_string.indexOf(",", second_comma + 1);
int v_pos = decoded_data_string.indexOf("V");
String lat = decoded_data_string.substring(first_comma + 1, second_comma);
String lon = decoded_data_string.substring(second_comma + 1 , third_comma);
String bat_voltage = decoded_data_string.substring(v_pos + 1, v_pos + 4);
server.send(200, "text/html", "OK");
WiFiClient client;
HTTPClient http;
if (http.begin(client, "http://insert your server here:insert your port/insert blynk sec auth t/update/V7?value=" + String(pos_index) + "&value=" + lat + "&value=" + lon + "&value=" + bat_voltage + "V")) {
int httpCode = http.GET();
if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String api_answer = http.getString();
}
}
http.end();
}
}