Jump to content




Redstone 2 Phone - receive a redstone signal as an SMS message


18 replies to this topic

#1 Forgotten_Boy

  • Members
  • 72 posts
  • LocationOntario, Canada

Posted 01 July 2015 - 05:42 AM

Tired of signing in to your server to see if that multi-day process to complete an Agrarian Skies quest is done?
Here's a solution I call "Redstone 2 Phone" which uses ComputerCraft's HTTP API to receive a redstone signal on your phone via SMS, or just on a web page where you can monitor the status.
It involves using a site I built to make the HTTP server part much simpler, and apologies in advance for promoting that here but there's no other way to demonstrate this.
I hope you ComputerCraft people can see the potential of making simpler use of ComputerCraft's HTTP capabilities to build great things by having a web server that eliminates most of what server programming requires.

Screenshot of the server side:
Posted Image

This page shows you how to get the redstone signal to your phone, and serves as the listener for your HTTP messages:
https://boomtree.com/r2p

To view that site you'll need Flash installed in your browser and it works best at a 1080p resolution. The server-side code is editable here, though the documentation is a little thin at the moment. ^_^

Also note you don't need a phone or a way to receive SMS to test it: simply install the r2p program using pastebin, paste in an R2P key (the one in the screenshot is not valid) and trigger a redstone signal by the computer. Then Refresh the page and you should see your signal as above. If you include a phone number the message will be green and you will receive the SMS message at the phone number you saved.

Try it yourself.
Step 1: install the program on your ComputerCraft computer.
The ComputerCraft r2p program is accessible via this Pastebin command:
pastebin get 533JxP5N r2p

This requires Minecraft 1.7.10 and is tested with ComputerCraft 1.73, though it should work with older versions that have HTTP support.
You'll also need to make sure your ComputerCraft install has HTTP enabled in ComputerCraft.cfg:

B:http_enable=true

Step 2: run the r2p program
Type r2p into your ComputerCraft computer. R2P will prompt you to enter a key.

Step 3: paste the R2P key into your ComputerCraft computer.
Visit the web page above and copy the R2P key by clicking the copy button or by manually copying the gibberish in the text field.
After hitting enter you will be prompted to enter the message you want to send; this is what you will receive on your phone.

Step 4: trigger a redstone signal on your ComputerCraft computer.
You probably know how to do that. :P

Step 5: click the Refresh button on the web page.
You should now be bringing a redstone signal right to your phone!

Edited by Forgotten_Boy, 02 July 2015 - 12:57 AM.


#2 lifewcody

  • Members
  • 143 posts
  • Locationstill looking....

Posted 01 July 2015 - 06:11 AM

Wow, this is awesome!

How did you get texting to work?

#3 Forgotten_Boy

  • Members
  • 72 posts
  • LocationOntario, Canada

Posted 01 July 2015 - 07:52 AM

The texting is handled by Twilio who have a perfectly simple HTTP API for sending SMS messages. Your r2p message reaches Boomtree which then calls Twilio. In this way it's possible to provide a service like this without revealing my Twilio secret key.

#4 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 01 July 2015 - 10:34 AM

Are you paying for this...

#5 Forgotten_Boy

  • Members
  • 72 posts
  • LocationOntario, Canada

Posted 01 July 2015 - 06:25 PM

Am I paying for the Twilio account and the server to run this? Indeed! The r2p page will give you 5 free text messages to test it out, and after that you have to pay to use it further. Because I'm hoping to avoid the obvious abuse by programs that send excessive text messages (and spend my cash excessively!).

#6 PokeAcer

  • Members
  • 143 posts

Posted 01 July 2015 - 07:55 PM

Does this work with UK mobiles? I just get this:
Posted Image
I've looked at Twillio's API and it should accept 07, I've also tried +44 (UK code)

#7 Forgotten_Boy

  • Members
  • 72 posts
  • LocationOntario, Canada

Posted 01 July 2015 - 09:07 PM

This should work with UK mobiles, at least according to Twilio. Assume it's coming from a North America phone number.
If you visit this link at boomtree you should see your Twilio message:
https://boomtree.com...target=Messages

You should see an HTTP response there; lets figure out what's going on.

#8 PokeAcer

  • Members
  • 143 posts

Posted 01 July 2015 - 09:17 PM

I got
Last response code: 400
Response Body: <?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse><RestException><Code>21211</Code><Message>
From Twillio:

Quote

Invalid 'To' Phone Number
And then when I tried +44 I got
Last response code: 400
Response Body: <?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse><RestException><Code>21408</Code><Message>
Twillio says:

Quote

Permission to send an SMS or MMS has not been enabled for the region indicated by the 'To' number
So it looks like you need to enable it.

Edited by PokeAcer, 01 July 2015 - 09:20 PM.


#9 Forgotten_Boy

  • Members
  • 72 posts
  • LocationOntario, Canada

Posted 01 July 2015 - 09:39 PM

Thanks for the debug! I've enabled a bunch more countries, including the UK. Try your +44 attempt again and it should work.

#10 PokeAcer

  • Members
  • 143 posts

Posted 01 July 2015 - 10:49 PM

View PostForgotten_Boy, on 01 July 2015 - 09:39 PM, said:

Thanks for the debug! I've enabled a bunch more countries, including the UK. Try your +44 attempt again and it should work.
Yay, it works now! Make sure you put a notice saying to add +[countrycode]

#11 Forgotten_Boy

  • Members
  • 72 posts
  • LocationOntario, Canada

Posted 01 July 2015 - 11:46 PM

Done!

#12 クデル

  • Members
  • 349 posts

Posted 02 July 2015 - 09:05 AM

Does this support Australian numbers (+61)?

#13 Forgotten_Boy

  • Members
  • 72 posts
  • LocationOntario, Canada

Posted 02 July 2015 - 04:21 PM

Yes indeed, Australia has been made available along with most of the "western" world. There's always the chance that a specific provider doesn't work, but for most countries Twilio claims 98% or better access.

#14 jaredallard

  • Members
  • 124 posts
  • LocationSeattle, WA

Posted 02 July 2015 - 04:26 PM

I love the idea, but I was wondering. Have you thought about making an app with push notifications enabled to negate the need for paying for SMS?

#15 Forgotten_Boy

  • Members
  • 72 posts
  • LocationOntario, Canada

Posted 02 July 2015 - 05:04 PM

Twilio doesn't make it easy to build push stuff, and here I was mostly interested in using their HTTP interface to build towards the next thing; I really wanted to use SMS. The /r2p page already provides a free way to monitor a signal away from the Minecraft server, albeit only at a PC with Flash.

However, the point of Boomtree is to build any kind of client connection, so you could use it to simply build an HTML page that mobile user-agents can view and monitor your signals that way. Boomtree doesn't do sockets yet so push notifications aren't going to happen without some extra work.

The source of r2p (and everything in Boomtree) is editable, though without a video tutorial yet complete it's for the intrepid only. Considering the entire r2p app is a few hundred lines, a basic HTML page that works on mobile wouldn't be very tough and would certainly be simpler than many of the amazing CC programs I've seen on here! You can see the XML that the client uses to draw the screen here; if that were accessed and rendered via an HTML client (or even in ComputerCraft!) rather than Flash then you're in business.

#16 PokeAcer

  • Members
  • 143 posts

Posted 02 July 2015 - 06:24 PM

Quick Question: Why not work out a method to turn a signal on/off via text?
Example: My number (+44770093921 - not real number, it's an Ofcom Drama Number) texts the r2p number saying 'ON <compuID> <direction>' and it'd text back saying '<compuID>'s Redstone signal on the <direction> has been turned on'
You could also get a few more phone numbers if people pay you enough. Also, how do you pay for it after the first 5?

#17 Forgotten_Boy

  • Members
  • 72 posts
  • LocationOntario, Canada

Posted 02 July 2015 - 06:57 PM

I'd like to implement replies yet to allow a full messaging environment from within Minecraft. Right now if you reply you receive a canned message.
You should see a "Buy more SMS messages" link right below the "Monitor your signals!" line if you've completed a signal from Minecraft. That link goes here:
https://boomtree.com/r2p/more

If you don't see anything at that page, please let me know and what browser you are using. That uses the Stripe payment widget and it's pretty finicky about SSL and sometimes breaks the page.

#18 PokeAcer

  • Members
  • 143 posts

Posted 02 July 2015 - 08:13 PM

would there be a way (at a higher cost) to pay you manually for an amount for UK texts?
it's only $0.04 per UK text, so I could pay you £2 ($3.12) for 78 if you'd allow this.

Edited by PokeAcer, 02 July 2015 - 08:13 PM.


#19 Forgotten_Boy

  • Members
  • 72 posts
  • LocationOntario, Canada

Posted 02 July 2015 - 09:21 PM

My goal is to charge the same markup for a UK text as for a US text, but I can't do anything manually at the moment. The dirty secret is that the much higher UK text rate is not implemented right now - buy a hundred messages and pay the US rate! Perhaps you'd like to debug that from the Twilio XML for me :) It's selling at a huge loss at the moment for UK customers and I make no guarantee how long it will last but I'm not working on that at the moment.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users