Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

python - rtl_433 on raspberry pi: Send data to api via http post

I'm receiving the weather data from my weather station with a dongle on my raspberry pi, that has internet connection via wifi. Now I want to send this data to a rails api/app to save it there in a database. The rails app runs on another server, so I want to post the data via http. How can I do this. I can't add the curl dependency to the rtl_433 project (https://github.com/merbanan/rtl_433) to send the data directly to my backend. Am I able to run the rtl_433 for example with a python script like:
rlt_433 -F json and take that output to send it to my backend or how can I realize that?

question from:https://stackoverflow.com/questions/65917930/rtl-433-on-raspberry-pi-send-data-to-api-via-http-post

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should be able to execute rtl_433 as a subprocess using the subprocess module. Normally you would just use subprocess.run, but since rtl_433 produces output until it is killed, you will need to use subprocess.Popen and parse the output.

Another option is to pipe the output of rtl_433 to your program and using input() or sys.stdin.readline() to read lines. Like rtl_433 -flags | python3 script.py.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...