0

I have been trying to externally log data to my home server with a little GSM modem and InfluxDB2 HTTP API- it is far away and needs to be external, just checking water levels and other system stuff.

I am struggeling to understand the correct payload and keys to give it in order for it to accept my data.

I am using an ESP32 and the requests module on Micro Python, using MicroPython_ESP32_psRAM_LoBo.

The GSM library I am using makes everything work as if I was connected to Wifi, I am pretty certian that my problem has nothing to do with the GSM side of things.

The system uses InfluxDB2 and Python3 ( Micro Python to be exact )

Current Setup

payload = {"header":"Authorization: Token CrAzYlOnG_ToKeN", "data-raw":"WaterWatcher1 Level=532,Volume=752.22,BattV=3.768,Temperature=25.36 1621434110"}

response = requests.post("http://xxx.xxx.xxx.xxx:8086/api/v2/write?org=Home_Org&bucket=BackYardInfo&precision=s", params=payload)

( xxx Replaced with my correct IP - Yes I have made sure this is correct and got my ISP to set it to static )

This gives me a constant Auth error :

W (3390149) HTTP_CLIENT: This request requires authentication, but does not provide header information for that

I have read over the InfluxDB2 docs and I still cant seem to get it correct, I seem to think that if I did this in InfluxDB Ver 1 it would have been easier but now I just want to try learn it this way.

I have entered the exact same data manually and that works fine ( changed the time stamps though )

I am pretty sure it boils down to me just not knowing how to send the data correctly with the requests module, any pointers and explanations would be a great help.

Spider999
  • 135
  • 1
  • 8
  • 17
  • The error says you need an authentification token in the header [this page](https://docs.influxdata.com/influxdb/v2.0/security/tokens/view-tokens/) seems to explain how to do that properly. – OneMadGypsy May 20 '21 at 02:29
  • Hi, thanks but I have tried that, I have the tokens and the other info I need to pass, but I do not know how to pass it corretly with the requests lib, I think I will have to try a different lib to get it to work. Thanks for your input though. – Spider999 May 21 '21 at 13:50

1 Answers1

0

I managed to find a solution after days of searching and trying new things.

Basically I used the mrequests lib ( https://github.com/SpotlightKid/mrequests )

With this I managed to get the whole thing working as expected using the following code - Done in Micropython

I did make a free account with No-IP to set my ISP external IP to a URL, I dont think this has a massive change but it is worth noting. I did try the older methods with this new URL and they still did not work.

Here is the new code with the mrequest lib.

import mrequests
url = "http://ni-ip-address:8086/api/v2/write?org=Home_org&bucket=backYardData&precision=s"

token = "Token CrazyLongToken"


DataString = "WaterWatcher1 Level=888,Volume=888.88,BattV=8.888,Temperature=25.36 1621694039"

res = mrequests.request("POST", url, headers={"Authorization":token}, data=DataString)

This works perfectly for me.

On a side note, I can also upload multiple points if I read them from a file but I had to put the newline char "\n" at the front of each of my lines not the end or Influx would not pars the data.

I think it boiled down to the urequest lib not being able to do headers as I needed them in post requests. I may have just been using it wrong but I feel that I did give it more than a fair go at getting it right where as this mrequests lib just worked perfectly.

Hope this helps anyone else out there one day.

Spider999
  • 135
  • 1
  • 8
  • 17