I have just completed my ESP32 noise sensor based on LoRaSoundkit. I forward the TTN data to my own server und from there via logstash pipeline to the API. The tricky think was to find the logstash commands to build the JSON structure.
input { pipeline { address => "sensor.community-noise" } }
filter {
# process data for sensor.community
mutate {
add_field => [ "[@metadata][app_id]", "%{[end_device_ids][application_ids][application_id]}" ]
add_field => [ "[@metadata][device_id]", "%{[end_device_ids][device_id]}" ]
} # mutate
#
# BEGIN device specific configuration section
# each TNN device (sensor) requires one configuration section
if ([@metadata][device_id] == "YOUR-TTN-DEVICENAME") {
mutate {
add_field => { "[@metadata][send_data]" => "true" }
add_field => { "[@metadata][sensor]" => "YOUR-NODE-ID" }
}
}
# END device specific configuration section
if ([@metadata][send_data] == "true") {
mutate {
add_field => { "software_version" => "1.0" }
}
ruby {
code => '
event.set("sensordatavalues", [
{"value" => event.get("[uplink_message][decoded_payload][la][avg]"),"value_type" => "noise_LAeq"},
{"value" => event.get("[uplink_message][decoded_payload][la][min]"),"value_type" => "noise_LA_min"},
{"value" => event.get("[uplink_message][decoded_payload][la][max]"),"value_type" => "noise_LA_max"}
] )
'
}
} #if
mutate { remove_field => ["app_id","@version","@timestamp","host","received_at","_source","headers","correlation_ids","uplink_message","end_device_ids"] }
} # filter
output {
# curl test command to upload parameters
# curl --location --request POST 'https://api.sensor.community/v1/push-sensor-data/' --header 'Content-Type:application/json' --header 'X-Pin:15' --header 'X-Sensor:YOUR-NODE-ID' --data-raw '{"software_version": "1.0", "sensordatavalues":[{"value_type":"noise_LAeq","value":"21.21"},{"value_type":"noise_LA_max","value":"22.22"}, {"value_type":"noise_LA_min","value":"23.23"}]}'
if ([@metadata][app_id] == "YOUR-TTN-APPLICATION-ID" and [@metadata][send_data] == "true") {
http {
url => "https://api.sensor.community/v1/push-sensor-data/"
#url => "http://localhost:1099"
http_method => "post"
format => "json"
headers => {
"X-Pin" => "15"
"X-Sensor" => "%{[@metadata][sensor]}"
}
} # http
# for DEBUG only
# file {
# path => "/tmp/sensor.community-%{[@metadata][device_id]}.log"
#
#}
#stdout {
# codec => rubydebug { metadata => true }
#}
} # if [@metadata][app_id]
} # output
The community version of Logstash is available at Download Logstash Free | Get Started Now | Elastic.
The ESP32 consumes 35 mA in the middle and now I will connect the device to my solar based PM sensor.
I send the noise data also to opensensemap with a second logstash pipeline.