need help with php code for sms based gate opener
michaelmonso
Posts: 19
im trying to make this project i saw online work for me. this guy used a spinneret and a cloud server called twilio to be able to text message his spinneret to have it trigger a servo to lock or unlock his door. i would like to do the same thing but to open or close my gate. i have a handle around his .spin project and i finally got twilio to work. between the two though he has a python django enviroment that parses the text message and sends the information to the spinneret. i cant get the django part to work but he said it could be written in php to work. im not familiar with php enough to do that code though. im looking for help from anyone that can take the following code written in python django and make a php document that does the same thing.
so he would text twilio "open" >twilio would foward this to his django script> django would parse and send his spinneret "o"> the spinneret would trigger the servo... but he is using the above script written in python i would like written in php because my host for the python file doesnt support the django enviroment he wrote the code in.
please help anyone.thanks.
import urllib2 def door(request): ''' This is plugged into a django env, but can really be used with anything. Twilio hits this URL, which pings the door and returns the response ''' doorurl = 'http://162.228.0.150:5001/' whitelist = [ "+18183798995", "+14179592671", ] fromnum = request.POST.get("From") body = request.POST.get("Body") if fromnum and body and fromnum in whitelist: if body == "open": doorurl = doorurl + '?1=o' elif body == "close": doorurl = doorurl + '?1=c' elif body == "status": pass try: doorres = urllib2.urlopen(doorurl, timeout = 10).read().strip() except: doorres = "door unresponsive" return HttpResponse('<Response><Sms>' + doorres + '</Sms></Response>', content_type="text/xml") raise Http404
so he would text twilio "open" >twilio would foward this to his django script> django would parse and send his spinneret "o"> the spinneret would trigger the servo... but he is using the above script written in python i would like written in php because my host for the python file doesnt support the django enviroment he wrote the code in.
please help anyone.thanks.
Comments
IMO, It would be easier to send the HTTP request directly to your Spinneret from twilio. Why relay through a secondary server?