LowPowerLab Forum

Software support => Pi Gateway => Topic started by: spark on October 26, 2015, 02:54:02 AM

Title: SMS Interface to GarageMote
Post by: spark on October 26, 2015, 02:54:02 AM
So I am having a sleepness night.  What better way to use the time than to hook up my moteino to an SMS interface.  I have a home server running Open Media Vault (Debian Linux).  This runs my backups, etc.  I am using nginx installed on this server to proxy the Moteino gateway web application.

I decided to write a short node application running on my home server that uses Twilio messaging service to provide 2-way SMS.  I thought this may be interesting for some folks here.

Here is a link to the code: https://gist.github.com/lookingcloudy/e23116430f1d757b6642

Assuming you have basic knowledge of Node.js, create a new directory on your server.  Copy over package.json and moteino_sms.js.  Run

npm install

to install all the dependencies.   Next, decide on what URL you want to use on your home server and configure that in your nginx proxy server.  Be sure to configure basic authentication.  Now, create your Twilio account.  You'll need to create a phone number, then make note of the Twilio SID and AuthID.  Configure the request URL for sms service using the URL you configured above.  Be sure include your basic authentication.

Finally, update moteino_sms.js with your settings.  All the settings are at the top of the file and should be self-explainatory.  Now you are ready to run your new sms gateway!

node moteino_sms.js

If you are ready for production mode, create a forever script, or service monitor of your choice.  That will be used to run the application in the background and keep it running.

Have fun!
Title: Re: SMS Interface to GarageMote
Post by: Felix on October 26, 2015, 08:01:28 AM
pretty cool stuff here brad, thanks for sharing this!
Title: Re: SMS Interface to GarageMote
Post by: HeneryH on October 28, 2015, 12:11:27 PM
Didn't look through the code but this could be very cool for my use-case which is an access control for a marina driveway entrance gate.

I'd need a security layer though to only allow texts from certain phone numbers to be authenticated to open the gate.

I'll look into this more!

Thanks
Joe
Title: Re: SMS Interface to GarageMote
Post by: spark on October 29, 2015, 11:34:50 PM
Cleaned up the code...and added a little extra functionality.  New code is posted in the same gist linked above.  I can now send:

open [n1] [n2]  - the numbers are optional.  N1 is the number of minutes to wait until open.  N2 is the number of minutes to wait, then automatically issue a close command.  Handy if I'm walking out the door and jumping on my motorcycle.

close [n1] - similar to above, waits n1 minutes to close the door.

@HeneryH - this would definitely work for that.  There is an array of authorized numbers in the configuration at the top.  It would be rather simple to get those from a database or a file.

Also - if you replace lodash with underscore in the dependencies, this very well might be able to run on the pi.  lodash is the speedier version of underscore and is interface compatible.  I haven't tried it yet though...