Page 1 of 1

How do I do an HTTP POST?

Posted: Mon Apr 29, 2019 2:06 am
by duckredbeard
Ok, this is my first project. Go easy on me. I would search, but I'm not even sure what the key words are that I should be using. Here is what I hope to accomplish...

My current garage door project has a limit switch that enables a light. An old Android phone monitors that light. When the garage door opens and the light comes on, it sends my phone a message, using Tasker and AutoRemote (enter task). My phone receives that message and displays a notification, showing a predetermined message and time stamp. When the door is closed and the light goes out, it is expected to send a different message (exit task), which again causes a different notification. The "exit task" of this does not always fire because it doesn't capture that the light went out if it had been on for more than a few minutes.

Using Tasker and Join, I am able to create a few URLs that will accomplish the same "trigger" event as the light being seen/unseen. If your browser hits on one of those URLs, my phone gets a keyword message. When it gets that keyword message, my phone displays a notification, based on the keyword (open or closed).

What I need the Pi to do is monitor the hi/lo state of the switch, or either throw of that switch, and "hit" the appropriate URL so that my phone gets the event.

TL;DR - I need the Pi to do HTTP POST when a switch is opened and closed.

Re: How do I do an HTTP POST?

Posted: Mon Apr 29, 2019 9:40 am
by neilgl
Maybe you could have a python program on the pi looking at the state of a switch connected to a pi GPIO pin, then send a POST to the approprate URL (using the python “requests” library). Note you don’t want more than 3.3 volts on the pi GPIO pins.

Also you could use curl from the pi command line to test the POSTs to the URLs.

Re: How do I do an HTTP POST?

Posted: Mon Apr 29, 2019 10:13 am
by duckredbeard
I would prefer the GPIO input be monitoring a ground/not ground state. How do I do the "requests" library?

I have seen some dialog on the curl method and it seems to be popular. I just don't know how to put it in python. I have zero experience with this other than research.

Re: How do I do an HTTP POST?

Posted: Mon Apr 29, 2019 1:51 pm
by scotty101
Python-requests is a very well documented library

Here is a link to the perform an HTTP POST ... t-requests

Re: How do I do an HTTP POST?

Posted: Mon Apr 29, 2019 3:10 pm
by duckredbeard
Got this going...

>>>r ="")

and I get the notification on my phone and living room lights turned on. Yes, that was the desired result. Now I just gotta get it to trigger with the switch(es). One piece at a time, I will get there.

And I thought Tasker was a steep learning curve!