Send data from weewx to farmOS- how can i do?

Hi!

I want to upload some data from my local weewx-system (running on a raspberry pi) to farmOS and wrote the following python-script to parse the data and load it up by curl:

import requests

from bs4 import BeautifulSoup

import json

import subprocess

url = “http://192.168.188.23/weewx

header = {“User-Agent”: ‘Mozilla/5.0 (Android 13; Mobile; rv:109.0) Gecko/116.0 Firefox/116.0’}

seite = requests.get(url, headers=header)

soup = BeautifulSoup(seite.content, ‘html.parser’)

temperatur = soup.find(“td”, text=“Aussentemperatur”).find_next_sibling(“td”).text

Remove the " C" from the temperature string

temperatur = temperatur.replace(" C", “”)

Timestamp generieren

import datetime

timestamp = datetime.datetime.now().isoformat()

Daten als JSON-String vorbereiten

data = {

"timestamp": timestamp,

"Temperatur": float(temperatur)

}

json_data = json.dumps(data)

JSON-Daten an die Ziel-URL mit curl senden

curl_command = ‘curl -H “Content-Type: application/json” -X POST -d '’ + json_data + ‘' https://lindhagen.farmos.net/api/data_stream/[privae_key]/data

subprocess.run(curl_command, shell=True, check=True)

When i run this script on the weewx-machine i get the html-code for the following result:

So, what can I do to solve this login-problem??

Hi @Lindhagen welcome to the forum! :smiley:

I think you might just need to change the URL that you are sending the POST request to.

It looks like you are sending to:

/api/data_stream/[key]/data

It should be:

/api/data_stream/[uuid]/data?private_key=[key]

Here is a screenshot of an example data stream I set up on a test site to show where you can find the correct URL for your data stream:

I got there by creating a new Sensor asset, and adding a Data Stream to it named value, then clicking on “value” on the sensor asset’s page (/asset/[id]), which brought me to /data_stream/[id]. The “Developer information” box available on that page has the URL and an example curl command for testing.

Thank you. Now it works… for the temperature… I have now to write more code for the other values like Humidity, ET, Wind etc… :wink:

2 Likes

Awesome! I’ve always wanted to try weewx with my weather station. If you feel like writing up a blog post for the farmOS Community Blog I’m sure others would love to learn from your experience!

Blog posts can be proposed as pull requests in this repo: GitHub - farmOS/farmOS-community-blog: Community content for the farmOS website

2 Likes