R-A
Posts: 15
Joined: Sun Sep 11, 2016 4:59 pm

how to post data to URL?

Sun Oct 01, 2017 6:34 pm

Hi,

I wonder if someone can help me?

I found some code on the internet (github) to read values from my solar inverter, but it's written in C. And I don't know C, but rather some PHP and Python.
So I want to modify the script to upload the values to http://www.emoncms.com either a GET or POST request. Their API supports the following format:

GET: https://emoncms.org/input/post?node=emo ... xxxxxxxxxx

POST: curl --data "node=1&data={power1:100,power2:200,power3:300}&apikey=xxxxxxxxxxxxxxxx" "https://emoncms.org/input/post"

API samples: https://emoncms.org/site/api#input

I can do this in Python, as follows:

Code: Select all

     r = requests.get("https://emoncms.org/input/post.json?node=1&json={Bedroom1Roof:" + str(myTempBed1Roof) + "}&apikey=" + APIKEY)
#      print(r.url)
#      r.status_code == requests.codes.ok
#      print(r.status_code)
"str(myTempBed1Roof)" is a variable string which I get from a DS18B20 temp sensor.


But, as I said, the current script is written in C, and I don't know how to accomplish this. Nor do I know how to re-write this code in Python.

Any help would be highly appreciated. I have searched the forums but the code I found is all for Python.

R-A
Posts: 15
Joined: Sun Sep 11, 2016 4:59 pm

Re: how to post data to URL?

Wed Oct 04, 2017 8:45 pm

Any help with this would be highly appreciated

ghans
Posts: 7361
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: how to post data to URL?

Wed Oct 04, 2017 10:08 pm

Use subprocess.Popen() to execute the C program and read its output.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4444
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: how to post data to URL?

Thu Oct 05, 2017 8:39 am

Post a link to the C code and someone may be helpful enough to do at least a cursory conversion to Python, or at least give some guidance as to what the C is doing and how you might replicate it in Python.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

R-A
Posts: 15
Joined: Sun Sep 11, 2016 4:59 pm

Re: how to post data to URL?

Fri Oct 06, 2017 7:26 pm

6by9 wrote:
Thu Oct 05, 2017 8:39 am
Post a link to the C code and someone may be helpful enough to do at least a cursory conversion to Python, or at least give some guidance as to what the C is doing and how you might replicate it in Python.
I didn't write the code, so I didn't think I could post the URL, but it's on github.com/manio/skymax-demo
The important piece of code is on https://github.com/manio/skymax-demo/bl ... r/main.cpp

c++ is a bit difficult for me to understand, though I understand and can code some (limited) Python.

ghans
Posts: 7361
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: how to post data to URL?

Sat Oct 07, 2017 12:49 pm

Why don't install that piece of software and play around a bit. This is what the Pi is about , after all.

Code: Select all

sudo apt-get update
sudo apt-get install cmake
git clone git://github.com/manio/skymax-demo.git
cd skymax-demo
mkdir out
cd out
cmake ..
make
(instructions copied nearly verbatim from the github page)

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

Return to “C/C++”

Who is online

Users browsing this forum: juanrubio and 3 guests