Besides my LoRa stuff I also got a wifi based Luftdaten sensor. This often suffers from connectivity issues so I want to connect it using LoRa. But it turns out to be far more difficult then I expected. I know some people did some attempts in the past but what I can find is quite shattered and I can’t get the picture as a whole.
What I would expect: Modify the luftdaten sensor and add a LoRa node -> to TTN backend -> decode payload and send it to a HTTP integration using API credentials-> results are on Luftdaten.
But:
- The limited number of examples I find does not seem to use any authentication.Yet calling the API (http://api.luftdaten.info/v1/push-sensor-data/) did result in a few ‘unauthorized’ messages though, but I can’t recreate it so it might have been a functional thing
- Some examples use an intermediate service (https://github.com/verschwoerhaus/ttn-ulm-muecke). I don’t understand why and I wonder if this is related to the fact that I don’t manage to get it working
- a simple piece of C# code (below) to test it resulted in an error “{“detail”:“Unsupported media type “text/plain; charset=utf-8” in request.”}” although I did set the content type to application/json instead of plain text.
Any clues how to proceed? Does anyone has an example how the TTN application payload decoding and integration would look like? The reason I find it in particular strange is that using LoRa for this would make much sense. And both TTN and Luftdaten are pretty common platforms… So am I on the wrong track and did I miss a reason that makes another approach much better?
string sensor = "16741";
string sensorValue = "";
string softwareVersion = "123";
HttpClient client = new HttpClient();
client.BaseAddress = url;
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
var result = client.PostAsync(url.ToString(), new StringContent("{\"sensor\": 16741, \"sampling_rate\": null, \"timestamp\": \"2020-01-02 09:29:41\", \"sensordatavalues\": [{\"id\":12628208575, \"value\":\"1.00\", \"value_type\":\"temperature\" },{\"value\":\"98.40\", \"id\":12628208576, \"value_type\":\"humidity\" }], \"software_version\": \"123\" }")).Result;
string json_res = await result.Content.ReadAsStringAsync();
Console.WriteLine(json_res);