drschlaak.com
  • Home
  • Raspberry Pi
    • 1-Raspberry PI - Model B - Set Up >
      • Hardware Details
    • 2-Intro to Linux/Raspian
    • 3-Intro to Python >
      • RasPi Python libraries
    • 4-RasPi and External Hardware
    • 5-GPIO & High Current Loads
    • 5b-Controlling RasPi Remotely >
      • 5c-Using a USB Flash Drive
    • 6-I2C
    • 7-Our 1st IOT Device
    • 8-A Fuller IoT Device
  • Musings
    • Career Related >
      • Should I consider electronics as a career?
    • For the Techy >
      • How to ... >
        • ... Drive a Simple DC Motor
      • Free Stuff >
        • MultiSim Blue
      • Tutorials ... >
        • Remembering the Resistor Color Code
        • VHDL & ZYBO for Absolute Beginners
      • A Flying Car
      • Get Ready for the New FM
      • Gifts for Geeks
  • Course Notes
    • Term 7/10 >
      • PROJ421 >
        • Introduction

Our First IOT Device

The Internet of Things (IOT or IoT) is the sum of our cloud connected devices that can be controlled by us and can communicate with us at anytime from anywhere. It is the front door that can email us when it is left open too long; it is the door bell that can turn on a camera and send us a live video stream of who is at the door; it is the panic button that can phone or email us when it is pressed. The IOT is limited only by our imagination.

In this first introduction to the IOT, we will examine a simple unsophisticated application - a panic button which will .....

IOT devices/applications need to connect to the cloud/Internet. This can be a wireless or wired connection. For now we will have our RasPi wired to the Internet.

Our RasPi can act as the server or we can used a cloud based server leaving our RasPi to handle the local bit manipulation and some third party can look after data accumulation, management, and analysis. We will use the later for this project. 

Browse to http://bluemix.net and sign-up for a trial/free account. You'll recieve a confirming email with a link on which you must click. Then sign in and follow the steps to set-up you Bluemix environment.

In the Terminal. enter git clone git://git.drogon.net/wiringPi. Watch the spelling. This downloads wiringPi which ...

Enter cd wiringPi to change directory. Then enter ./build to compile the wiringPi code.

Enter curl -LO https://github.com/ibm-messaging/iot-raspberrypi/releases/download/1.0.2/iot_1.0-1armhf.deb. This downloads the IOT library we need.

Enter sudo dpkg -i iot_1.0-1_armhf.deb. This install the IOT library we just downloaded.

Enter service iot getdeviceid. This will print your unique IOT Raspi device id. It will be something like b827eb0409f5. Make note of this id.

In the web browser, goto to http://bluemix.net and log in if not already. Click on Catalog at the top of the screen. Scroll to the the very bottom of the window and click on Internet of Thing Platform. On the right of the screen, change the Service name: to iot-python. Ensure the App: selection is Leave unbound. Click the Create button. If your get an error during creation, try again.

On the next page, click Launch dashboard. Move the mouse to the left edge of the screen to open the icon tools menu.. Click Devices. Click + Add Device. In the next window click Create device type. In the next window, click Create device type. Enter raspberrypi into the Name field. Click the Next link in the lower right.

In the next window, enter the unique device id obtained earlier. Click the Next link in the lower right. In the next window (Metadata) click Next.

In the Security window, we will let IBM give us an Identification token so click Next, In the Summary window, click Next.

In the Credentials window, make note of all the relevant information especially the Identification Token. This is the only time you will see it and it is required for your RasPi to talk to the IBM service. When you have recorded this information, close the window by clicking on the X in the upper right; do not close the browser

Move the mouse to the left edge to open the icon tools menu. Click Access. Click API Keys. Click + Generate API Keys. Make note of the information generated as it will be required later. Click Finish.

In the Terminal, enter sudo nano /etc/iotsample-raspberrypi/device.cfg. Enter information from the final screen in the previous section in this format:
#this is raspberry pi stuff
​org=xxxxxxxxx
type=raspberrypi
id=xxxxxxxxxxxxx
auth-method=token
auth-token=xxxxxxxxxxxxxxx


where the xxxxxxxx is replaced with the pertinent information.

Press CNTL X, Yes to save and exit nano.

Enter sudo service iot restart to enable communication between our RasPi and the IOT service.

Now to download some python code. In the Terminal, enter git clone https://github.com/IBM-Bluemix/python-iot-raspberry-pi.git.

Enter cd python-iot-raspberry-pi to change directory.

Enter sudo apt-get install python-pip python3-pip. This install pip for both python2 and python3.

Enter sudo pip install -r requirements.txt. This downloads a package called Flask.

In the Terminal, enter sudo nano ~/device.cfg. Enter information from the Bluemix website in the previous section in this format:
#this is Bluemix application stuff
​org=xxxxxxxxx            # same as before
id=xxxxxxxxxxxxx      # same as before
auth-method=apikey
auth-key=xxxxxxxxxxxxxxxx         # Bluemix key
auth-token=xxxxxxxxxxxxxxx       # Bluemix token

Picture









​The pinout of the RasPi's P1 connector is again given at left for reference. Notice that some GPIO pin assignments change from Revision 1 to Revision 2 and beyond.

Circuits in this lesson assume a Rasberry Pi Model B version 2. If you have a Raspberry Pi Model B version 1, change all references to GPIO27 to GPIO21.





copyright @ 2014, 2015, 2016, 2017
drschlaak.com
✕