Difference between revisions of "Thing Dispenser"

From MC Chem Wiki
Jump to navigation Jump to search
 
(35 intermediate revisions by the same user not shown)
Line 35: Line 35:
 
::b) install Ardruino software (this is also described at the end of [http://esr.monmsci.net/wiki/index.php/Raspberry_Pi this] page).
 
::b) install Ardruino software (this is also described at the end of [http://esr.monmsci.net/wiki/index.php/Raspberry_Pi this] page).
 
::c) visit Rich Nelson's [https://github.com/rmn388 GitHub page] and select the [https://github.com/rmn388/dog-treat-dispenser dog-treat-dispenser]
 
::c) visit Rich Nelson's [https://github.com/rmn388 GitHub page] and select the [https://github.com/rmn388/dog-treat-dispenser dog-treat-dispenser]
::d) follow the directions shown in the [https://github.com/rmn388/dog-treat-dispenser/blob/master/README.md Readme] '''WARNING: this tutorial is not yet complete*:)'''
+
::d) follow the directions shown in the [https://github.com/rmn388/dog-treat-dispenser/blob/master/README.md Readme] '''(WARNING: this tutorial is not yet complete)'''
:::i) during the setup you will be asked for:
 
:::::''twilio_phone_number = "+###########" #Your unique Twilio phone number''
 
:::::''twilio_account_sid = "#################################" #Your Twilio Account SID''
 
:::::''twilio_auth_token  = "################################" #Your Twilio Auth Token''
 
  
====How to get Twilio Phone Number====
+
====Software Install, Part 1 of 4====
[https://youtu.be/rrx4ux-hChw YouTube Video]
+
:Here is a summary of a few "Terminal" inputs:
:1) Go to Twilio.com
+
::$ git clone https://github.com/rmn388/dog-treat-dispenser (this copies files needed from the developers website)
 +
::$ cd dog-treat-dispenser (to move into the project directory)
 +
::$ python3 -m pip install --user virtualenv (1st step to install a virtual environment for convenience)
 +
::$ python3 -m virtualenv env (2nd step  to install a virtual environment for convenience)
 +
::$ source env/bin/activate (''THIS NEEDS TO BE DONE EACH TIME YOU WANT TO WORK IN THIS ENVIRONMENT''...you will see a (env) in front of the prompt.)
 +
::$ pip install -r requirements.txt (needs to only be done once)
 +
::Now you will need to make a file called ''config.py''
 +
:::During the editing of the ''config.py'' configuration file,  you will be asked for:
 +
:::''twilio_phone_number = "+###########" #Your unique Twilio phone number''
 +
:::''twilio_account_sid = "#################################" #Your Twilio Account SID''
 +
:::''twilio_auth_token  = "################################" #Your Twilio Auth Token''
 +
:::'''''All of the items above can be found from your Twilio Account (see below, Part X)''''' You do not need all the API Credentials in order to continue...
 +
::$ python app.py (this starts the server running; the server is then shut down by typing CTRL+C)
 +
 
 +
====Software Install, Part 2 of 4====
 +
''How to get Twilio Account/Phone Number''
 +
 
 +
[https://youtu.be/rrx4ux-hChw YouTube Video: Getting Started with Twilio]
 +
:1) Go to [www.Twilio.com Twilio.com]
 
:2) Select "Sign up"...and then "Get Started"
 
:2) Select "Sign up"...and then "Get Started"
::- when asked, "which product do you plan to use first?" choose '''I'm just exploring'''
+
::- when asked, "which product do you plan to use first?" choose ''I'm just exploring''
::- when asked "what are you building?" choose '''I don't have a project in mind'''
+
::- when asked "what are you building?" choose ''I don't have a project in mind''
 
::- you will need to give Twilio an existing phone number, like your personal cell number.
 
::- you will need to give Twilio an existing phone number, like your personal cell number.
::- After the intro, you will want to select Programmable SMS in the left tool bar while in the '''Console'''...then choose get started...
+
::- After the intro, you will want to select Programmable SMS in the left tool bar while in the '''Console'''...then choose get started...by the way '''SMS''' means ''simple message system''.
 
::- then follow the directions in order to get a new phone number...
 
::- then follow the directions in order to get a new phone number...
  
 +
The following video is interesting (but not basic)...it discusses '''Twilio''' and then towards the end '''NGROK'''...which will be discussed below.
 +
::[https://youtu.be/cZeCz_QOoXw setting up the phone number to respond to a txt message]
 +
 +
Once your account is setup, you will need to make a project for which the phone number is associated with. You can then go to the Dashboard menu to find the following items that need to be added to the ''config.py'' file created above:
 +
:- Phone Number: XXX-XXX-XXXX
 +
:- ACCOUNT SID (aka: twilio_account_sid)
 +
:- AUTH TOKEN (aka: twilio_auth_token)
  
 +
'''You will need to do a few more configuration step to your Twilio project, but of now we can move on...'''
  
[[:File:Screen Shot 2018-06-19 at 1.26.24 PM.png]]
+
Why more steps?...well, if we were using a static IP address (one that does not change and is accessable from any computer) for the raspberry pi, then we could not have to build a "tunnel" using NGROK...see below...
  
::[https://youtu.be/cZeCz_QOoXw setting up the phone number to respond to a txt message]
+
====Software Install, Part 3 of 4====
 +
Our Raspberry pi is connected to the internet thru the wifi and as a result, the "address" or IP address for the pi is not directly accessable to the "world" even though we have set it up as a "server." So we must setup what is called a "tunnel"...thru the wifi router to the pi server. This tunnel is setup using software called NGROK.
 +
 
 +
:1) Download NGROK software...
 +
::[https://dashboard.ngrok.com/get-started Setting up ngrok in order to setup a "tunnel" to a local computer]
 +
:2) We are using port 2244...not sure why?
  
::[https://dashboard.ngrok.com/get-started setting up ngrok in order to setup a "tunnel" to a local computer]
+
====Software Install, Part 4 of 4====
 +
To initiate the webserver...
  
1) First off, you need to have a phone number which can receive a txt message which is ultimately connected to the device. This is done by setting up an account with a online company called [https://www.twilio.com/ Twilio]. Getting a phone number is relatively easy...a trail Twilio account give you a credit of $15 to spend before you need to connect a credit card to the account.
+
:1) go to cd dog-treat-dispenser directory
 +
:2) Activate the env (''source env/bin/activate'')
 +
:3) type python app.py
 +
:4) open a second terminal window and type ./ngrok http 2244
 +
::A forwarding IP address (http address will be shown - new one every time you initiate ngrok)
 +
:5) cut/paste this ngrok URL into the "Messaging: A message comes in 'webhook' in Twilio.
 +
:: (you can also test this new URL by pasting it into a web browser...it should say "Marker Dispenser Server is live")
  
 
====Web Resources====
 
====Web Resources====

Latest revision as of 15:16, 20 June 2018

This is not an easy project, but i believe it is doable (?). This project will create a physical device that will dispense a "thing" (dog treat or dry erase marker) when a txt message is sent to a phone number. The physical device contains a Raspberry Pi micro-computer.

This project was described in the March 2018 MAKE magazine (MAKEzine), here

To get started, I found the following video to be useful; if this physical device is going to respond to a txt message, then there must be some link between the act of sending the txt and the dispensing of the thing. In the following video, a basic description of something called an API (Application Programming Interface) is presented here

In this above video, the analogy of a restaurant is presented. As you sit at a table, you need to send information (your order) to the kitchen to get food. The "API" is the waitperson.

STEP 1...you tell the waitperson what you want to order,
STEP 2...the waitperson goes to the kitchen and tells to cook what to prepare, then
STEP 3...the waitperson then brings you your food.

Similarly, as i sit at my work desk, and i want a device to do something (like dispense a treat to my dog) the API controls the communications between me and the device...

STEP 1...I send a txt to the device,
STEP 2...the device executes the command, and then
STEP 3...the device sends a txt back to me indicating the commend has bee executed.

On to the actual setup...

Hardware configuration (the easy part)

You will need to build a device. In the original article a Raspberry Pi is connected to an Arduino board, which is in turn connected to a servo motor to actuate the dispensing. This is actually the easiest part of the project. Here are a few pictures (Note: the RP is not connected to mouse, keyboard, or monitor):

IMG 0320.JPG

IMG 0321.JPG

IMG 0322.JPG

IMG 0323.JPG

IMG 0324.JPG

Software configuration (the hard part)

a) setup a raspberry pi (see this page).
b) install Ardruino software (this is also described at the end of this page).
c) visit Rich Nelson's GitHub page and select the dog-treat-dispenser
d) follow the directions shown in the Readme (WARNING: this tutorial is not yet complete)

Software Install, Part 1 of 4

Here is a summary of a few "Terminal" inputs:
$ git clone https://github.com/rmn388/dog-treat-dispenser (this copies files needed from the developers website)
$ cd dog-treat-dispenser (to move into the project directory)
$ python3 -m pip install --user virtualenv (1st step to install a virtual environment for convenience)
$ python3 -m virtualenv env (2nd step to install a virtual environment for convenience)
$ source env/bin/activate (THIS NEEDS TO BE DONE EACH TIME YOU WANT TO WORK IN THIS ENVIRONMENT...you will see a (env) in front of the prompt.)
$ pip install -r requirements.txt (needs to only be done once)
Now you will need to make a file called config.py
During the editing of the config.py configuration file, you will be asked for:
twilio_phone_number = "+###########" #Your unique Twilio phone number
twilio_account_sid = "#################################" #Your Twilio Account SID
twilio_auth_token = "################################" #Your Twilio Auth Token
All of the items above can be found from your Twilio Account (see below, Part X) You do not need all the API Credentials in order to continue...
$ python app.py (this starts the server running; the server is then shut down by typing CTRL+C)

Software Install, Part 2 of 4

How to get Twilio Account/Phone Number

YouTube Video: Getting Started with Twilio

1) Go to [www.Twilio.com Twilio.com]
2) Select "Sign up"...and then "Get Started"
- when asked, "which product do you plan to use first?" choose I'm just exploring
- when asked "what are you building?" choose I don't have a project in mind
- you will need to give Twilio an existing phone number, like your personal cell number.
- After the intro, you will want to select Programmable SMS in the left tool bar while in the Console...then choose get started...by the way SMS means simple message system.
- then follow the directions in order to get a new phone number...

The following video is interesting (but not basic)...it discusses Twilio and then towards the end NGROK...which will be discussed below.

setting up the phone number to respond to a txt message

Once your account is setup, you will need to make a project for which the phone number is associated with. You can then go to the Dashboard menu to find the following items that need to be added to the config.py file created above:

- Phone Number: XXX-XXX-XXXX
- ACCOUNT SID (aka: twilio_account_sid)
- AUTH TOKEN (aka: twilio_auth_token)

You will need to do a few more configuration step to your Twilio project, but of now we can move on...

Why more steps?...well, if we were using a static IP address (one that does not change and is accessable from any computer) for the raspberry pi, then we could not have to build a "tunnel" using NGROK...see below...

Software Install, Part 3 of 4

Our Raspberry pi is connected to the internet thru the wifi and as a result, the "address" or IP address for the pi is not directly accessable to the "world" even though we have set it up as a "server." So we must setup what is called a "tunnel"...thru the wifi router to the pi server. This tunnel is setup using software called NGROK.

1) Download NGROK software...
Setting up ngrok in order to setup a "tunnel" to a local computer
2) We are using port 2244...not sure why?

Software Install, Part 4 of 4

To initiate the webserver...

1) go to cd dog-treat-dispenser directory
2) Activate the env (source env/bin/activate)
3) type python app.py
4) open a second terminal window and type ./ngrok http 2244
A forwarding IP address (http address will be shown - new one every time you initiate ngrok)
5) cut/paste this ngrok URL into the "Messaging: A message comes in 'webhook' in Twilio.
(you can also test this new URL by pasting it into a web browser...it should say "Marker Dispenser Server is live")

Web Resources