I’m very new to this and in all the documentation and community forums I haven’t found how I would make the core do a POST or GET request in response to a pin being set high or low.
I can’t imagine I’m the only one wanting to do this, so if someone could point me in the right direction I would greatly appreciate it.
A GET request should be really similar, just switch the method and include the parameters in the url instead of in the body, something like… (I haven’t tested this), where LIB_DOMAIN is a hostname from above:
I’m very new all around (both to Spark Core and coding) and I was working on a project using the Spark Core and a PIR sensor to send me a text message when motion is detected (I had seen the idea for the Spark Core referenced in Make Magazine issue #36).
In the article they mentioned using Twilio to send the text message. I’m wondering if anyone has written similar code but using Twilio to send a message?
I suspect the easiest way to do this right now would be for you to have code running on a website or server somewhere running functions or checking variables on the core, and then perform the Twilio API hits from your server. Here’s their quickstart guide for sending SMS: http://www.twilio.com/docs/quickstart/php/sms/sending-via-rest
I think this will become a lot easier when the Spark Cloud supports postback requests, in which case you’d be able to trigger a Twilio SMS with a simple Spark.Event call.
Does anyone know exactly how much it would cost to send SMS via Twilio? Looking at the pricing here, it seems like 2 cents USD per SMS. Anyone have experience with this?
I think, if you’re using a developer account, you can text and call your main phone # almost as much as you want. When you start texting or calling other phone numbers then you have to pay. – I think if you stay within your country, it’s only 0.75 cents (3/4 of a cent) per message?
Good question! There are a lot of ways to accomplish this server side. If you want to cause something to happen, or save information when your core makes a HTTP request (GET, POST, etc), then you probably want some code running on the server. This depends on what your hosting environment is (Windows, Linux, etc), and what languages your web server supports ( for example: PHP, Python, Java, Node.js, C#, etc). Most low-cost shared hosting plans support PHP, so for example, if you wanted to POST a variable to a page, you could create a page test.php that contained:
( http://www.php.net/manual/en/reserved.variables.post.php )
my Problem was on how to get the variable which i send out of the POST variable. I changed the protocoll and the content type. Now it works. For testing i wrote the POST Request in a axtra .txt file. Everything works fine.
You are never reading the response back from the web server and you are looping doing the GET requests as fast as possible. You need to wait for a response with client.available() and then either read or flush those bytes.
Thanks @bko I’ll give that a shot. I was tailing the HTTP logs on the server I was making the request to and only saw 1 request come in, so I assumed the core was locking up after the first. But will try again tonight and report back.