Overview

Skill Level: Beginner

Step-by-step

  1. Ingredient :

    Hardware Requirements

    PTK-STM32F207 [ Part-Number : 80K-F207IT ]Visit our website : (http://www.microtime.com.tw) , Or contact us : sales@microtime.com.tw 

    The platform contains the following sensors :

    • Touch screen
    • Accelerometer
    • Temperature sensor
    • Light sensor
    • Potentiometer
    • Joysticks
  2. Prepare :

    Get your device ready

    1. Software Installation :
      • Unpack the package and obtain the PTK product CD
      • Locate and run the setup executable
        setup_PTK-STM32F207_DEV_BAS_BIN_xxx_xxx.exe
      • The default installation path will be at :
        Drive:MicrotimePTK


      • Find “PTK-MCU-STM32F207 User Guide.pdf” and check section 1.3.2 to accomplish the following software installations
        • ePBB : The project tree for PTK software development.
        • IAR EWARM : The compile and debug IDE for Cortex-M processors
      • Find “ePBB Development Guide.pdf” and check
        “Appendix-A : About Micrium kernel source” to get uC/OS-II or uC/OS-III source code and Fix-Up ePBB with the kernel source
    2. Hardware Installation :
      • Unpack the package and get the PTK development modules
      • Check section 1.3.1 of “PTK-MCU-STM32F207 User Guide.pdf” to accomplish the following hardware installations
        • Plug MCU, BASE and TFT module all together.
          (Modules should be assemblied before product being delivered)
        • Install debug probe (JTAG-ICE) for code burning and debugging
      • Connect device to a network with Internet access using an ethernet cable

  3. Connect (Quickstart) :

    IBM Watson IoT Platform Quickstart connection

    1. Open the following project workspace within IAR-EWARM IDE
      Drive:MicrotimePTKePBBApplicationsProjectsPTK-STM32F207EWARM-V6OS_uCOS-IIbase_MQTTdemo.eww


    2. Since DHCP and DNS are not supported at this release, you need to manually resolve the MQTT host ip and setup static ip for your device (PTK-STM32F207).
    3. To resolve the MQTT host ip, try the following PC console command :
      ping quickstart.messaging.internetofthings.ibmcloud.com

      Note :
      Just ignore the message “Response timed out.”

    4. Take note and mark the IP (184.172.124.189) that was resolved as MQTT_HOST_IP.
    5. To allocate a static ip for PTK-STM32F207 and mark the IP (192.168.0.100) that was allocated as APP_TCPIP_CFG_IF_IP_ADDR_STR
    6. Expand the project folder, open the following config file
      Drive:MicrotimePTKePBBApplicationsProjectsPTK-STM32F207EWARM-V6OS_uCOS-IIsrcMQTT_cfg.h


      and modify the configuration details accordingly.
      Note :
      The IP specified are examples only, you should change the settings according to the results you got in step-4 and step-5.

      ...#define IBM_CLOUD//#define USE_DHCP//#define USE_DNS//#define USE_WIFI_GS2100M...//----- Network Configuration #ifndef USE_WIFI_GS2100M    #ifndef USE_DHCP        #define APP_TCPIP_CFG_DHCPc_MODULE_EN   0u        #define APP_TCPIP_CFG_IF_IP_ADDR_STR    "192.168.0.100"        #define APP_TCPIP_CFG_IF_MASK_STR       "255.255.255.0"        #define APP_TCPIP_CFG_IF_GATEWAY_STR    "192.168.0.1"...    #ifndef USE_DNS        #undef  MQTT_HOST_NAME        #define MQTT_HOST_IP                    "184.172.124.189"...#if (1)                                         //Quickstart Mode    #define ORG             "quickstart"...
    7. Within the IAR-EWARM IDE
      • Select “MQTT_No_DHCP_DNS” configuration
      • Make (Build) the project (Ensure that there is no error occurred)
      • Use “Download and debug” command to burn the code
      • Click the “Go” command or press the reset button (S1) on the upper right corner of LCD board to run the downloaded program

      • Now the device is running in Quickstart mode
    8. The running application will connect to the IBM quickstart service and start sending data periodically. Once connected, device will keep generating beep sound to showe us the tempo of message publishing.
  4. Visualize (Quickstart) :

    Real-time visualization of device data can be achieved by visiting the IBM Watson IoT Platform web page specific to your platform.

    1. The LCD panel of PTK-STM32F207 shows informations such as ORG ID, TYPE ID, Device ID, message count and sensor output
    2. Note the Device ID for later use
    3. Get into the Quickstart page, enter the device ID and view the sensor data online. To do so you may click Here
  5. Viewing messages by your way (Quickstart) :

    1. Create an application through IBM Bluemix
      • Go to IBM Bluemix
      • If you are an existing IBM Bluemix user log in as usual. If you are new to Bluemix you can sign up for their free 30 day trial.
      • From your Bluemix dashboard :
        • Under “Application” click “Create an APP”
        • Select that you would like to create a “Web” app
        • Click “Browse Boilerplates” and click “Browse Boilerplates” once more
        • Next to “Boilerplates”, select “Internet of Things Platform”
      • Finish adding the app by completing the following steps :
        • Provide a name for your application
        • Optionally modify the host name if required
        • Click the CREATE button
        • Wait for your aplication to start
      • Enter Node-RED application’s landing page
        • Once your application starts click the application URL to open the Node-RED landing page

      • Scroll down the Node-RED Internet of Things landing page and select the “Go to your Node-RED flow editor” button
    2. Connect your application with unregistered devices
      Using the Node-RED work flow editor you can configure your application to work with your connected devices.
      • Remove all of the existing sample nodes from the sheet
      • Create a new ibmiot input node :
        • Drag an ibmiot node from the input section of the node palette on the left hand side of the screen and drop it on the sheet
        • Double click the ibmiot node in your Node-RED flow editor
        • In the Authentication type field, select Quickstart from the pull-down list.
        • Enter the device ID of your board into the Device ID field. The device ID is displayed on the LCD screen of PTK-STM32F207
        • Click OK to confirm and close the edit window.
      • Create new debug output node :
        • Drag a debug node from the output section of the node palette on the left hand side of the screen and drop it on the sheet
      • To wire them together, just connecting the output of the “IBM IoT App In” node to the input of the “msg payload” node.
      • Deploy the application (Node-RED)
        • Look for the deploy button in the upper right hand corner of your Node-RED flow editor and it should be colored red.
        • Click the Deploy button to deploy your flow. (button should be turned gray)
      • Inspecting the messages coming from your device
        • Select the debug pane on the right (info is displayed by default)
        • You will see that the flow is generating Light Status messages.
          Note :
          If you can’t see it check that the switch on the right of debug node is “on”.
    3. Add more process logic in the application
      Now we would like to check the sensor output (light intensity) and dump message based on a threshold.
      • Create a threshold checking node to check the output value of light sensor
        • Drag a switch node from the function section of the node palette and drop it on the sheet.
        • Double click the switch node and setup the rules as shown below.

          Naming the node as “Light Check”
        • Click OK to confirm and close the edit window.
        • Now the switch node has two outputs, upper one for rule-1 and the lower one for rule-2
      • Create function nodes to receive messages from the trigger outputs of switch node
        • Drag a function node from the function section of the node palette and drop it on the sheet
        • Double click on the function node to open the javascript editor. Replace the existing code with the following :
            msg.payload = "Light"                    return msg;
        • Naming the node as “Light”
        • Click OK to confirm and close the edit window.
        • Use the same way to create another function node with the following javascript code
            msg.payload = "Dark"                     return msg;;
        • Naming the node as “Dark”
      • Wiring them together as shown below

      • Be remember to deploy the application each time when design is changed
      • Inspecting the changes of debug messages
        • Normally the “Light” message will be shown on debug pane
        • Now blocking the light that inject to the light sensor, this causes message “Dark” be shown on debug pane
          Note :
          The light sensor (U3) can be found on lower left corner of PTK-STM32F207
  6. Control your device through IBM Cloud (Registered) :

    1. Add IoT Service to your application
      Add the Internet of Things Bluemix service to your application, this creates a private IBM Watson IoT Platform organisation that you can register your device to.
      • Select the Internet of Things service by completing the following steps from your Bluemix dashboard
        • Under “Services”, click “Add a service or API”
        • Next to “Internet of Things”, select “Internet of Things”
      • Finish adding the service by completing the following steps
        • Select the application you just created to bind this service to
        • Optionally modify the service name and click the CREATE button
        • Select to RESTAGE your application when prompted.
    2. Register a device to your IBM Watson IoT Platform organisation
      • Click the Internet of Things service you just added to your application
      • Now you are on the IoT service dashboard page
      • Select “Launch dashboard” to open your IBM Watson IoT Platform organisation.
      • Select the Devices tab
      • Select Add Device
      • Enter a device type and device ID, then click “Continue”
        (Device type and ID can be found on LCD screen of PTK-STM32F207)
      • During the device registration process you will get device properties, copy these when you get them. They should look like this:
              org=vs9qqv      type=PTK-STM32F207      id=beefbeef0001      auth-method=token      auth-token=8MSW*8RMm@BkG9U3!p
      • Click “Done” to end the registration process.
    3. Setup registration credentials onto the device
      • Resolve the MQTT host ip by using the following PC console command.
        ping vs9qqv.messaging.internetofthings.ibmcloud.com

        Note:
        Replace the org field, vs9qqv, with what you really got in step-2.

      • Take note and mark the IP (e.g. 23.246.232.210) that was resolved as MQTT_HOST_IP
      • Again, open the MQTT_cfg.h file and make the following changes
        ...    #ifndef USE_DNS        #undef  MQTT_HOST_NAME        #define MQTT_HOST_IP                    "23.246.232.210"...#if (0)                                         //Quickstart Mode    ...#else                                           //Registered Mode    #define ORG             "vs9qqv"            //Replace with your org    #define DEVICE_TYPE     "PTK-STM32F207"     //    #define AUTH_METHOD     "token"             //    #define AUTH_TOKEN      "8MSW*8RMm@BkG9U3!p"//Replace with your auth-token#endif...
      • Within the IAR-EWARM IDE (As described earlier)
        • Make, download and run the code
        • Now the device is running in Registered mode
      • The application will connect to the organisation you just created in the IBM Watson IoT Platform service and start sending data periodically
    4. Connect your application with registered device
      • Return to your application dashboard in IBM Bluemix
      • Click the application URL to open the Node-RED Internet of Things landing page
      • Enter Node-RED flow editor
      • Double click the “IBM IoT App In” node in your Node-RED flow editor
      • In the Authentication type field, select Bluemix Service from the pull-down list.
      • Ensure that the node is configured with the following parameters :
      • Click OK and then Deploy the application again.
      • Look at the debug pane to see the events and messages received from the devices that was registered onto your organization.
      • You can also configure the IBM IoT App In node to subscribe events from a specific device ID such as beefbeef0001 in our case.
    5. Manually to send commands from your application (Node-RED)
      When device is running in registered mode you can send it commands from an Watson IoT Platform and device processes commands accordingly.
      • You can try this out by writing applications which connect to the IBM Watson IoT Platform and publishe messages to the device.
        You can do this in Node-RED.
      • We start from dragging an inject node from the input section of the node palette and dropping it on the sheet
      • Double click on the inject node and setup the properties as follows. This may inject message “{“beep”:5}” to the next node
      • Now drag an ibmiot node from the output section of the node palette and drop it on the sheet
      • Double click on ibmiot node and setup the properties as follows
        The Device ID should be setup properly, get it on PTK LCD screen
      • Wiring them together and deploying the application again.
      • INormally you will hear the beep as response of the manual triggering of inject node.
      • To trigger the message manually, just clicking the switch on the left side of inject node. A message “{“beep”:5}” is “injected” to
        “IBM IoT App Out” node which will then publish command messages to device.
    6. Controlling your device automatically
      So far we’ve learned about how to control the device manually through IBM cloud. It will be cool, if we can control it automatically.
      Here is our plan : “Beeping control by light intensity”
      To do so by completing the following steps :
      • Setup a function node to check the level of light intensity
        • Drag a function node from the function section of the node palette and drop it on the sheet
        • Double click on the function node to open the javascript editor. Replace the existing code with the following :
          if(msg.payload.d.Light < 100) {    msg.payload = "{"beep":3}";    return msg;}
        • Naming the node as “Light Ctrl”
        • Click OK to confirm and close the edit window.
      • Wiring the input of function node to “IBM IoT App In” node.
      • Wiring the output of function node to “IBM IoT App Out” node.
      • Again, don’t forget to deploy the design. Below shows the diagram of the flow.
      • Put your hand on top of the light sensor (U4) this may decrease the light intensity that the sensor can detect. Once the light level is lower than the preset value, 100 Lux in our design, on board buzzer will be activated.
  7. The white board application (Registered) :

    In this section, we build a collaborative application (Whiteboard) with two PTK devices and IBM Watson IoT service. With this appliation, user can draw on a shared canvas (PTK LCD) in real time.

    1. To setup one more device (PTK-STM32F207) for this application
      • Just checking the previous section “Connect (Quickstart)” and following the steps to complete the quickstart application for the new device.
      • Check the LCD screen of the new device and note the Device ID for later use.
      • Refer to the steps in section “Visualize (Quickstart)” and check if the data can be seen on the cloud.
    2. Register the new setup device to your IBM Watson IoT Platform organisation
      • In IBM Watson IoT Platform dashboard click on Devices tab
      • Select Add Device, enter a device type and device ID.
        (Type and ID are displayed on LCD screen of PTK-STM32F207)
      • Get device properties during the device registration process.They should look like this:
            org=vs9qqv    type=PTK-STM32F207    id=beefbeef0002    auth-method=token    auth-token=X*l5X!(SkF&c3RJVN@
    3. Setup registration credentials onto the new added device
      • Using the following command to resolve the MQTT host ip
        ping vs9qqv.messaging.internetofthings.ibmcloud.com
      • Take note and mark the IP (23.246.232.210) that was resolved as MQTT_HOST_IP
      • Again, open the MQTT_cfg.h file and make the following changes
        ...    #ifndef USE_DNS        #undef  MQTT_HOST_NAME        #define MQTT_HOST_IP                    "23.246.232.210"...#if (0)                                         //Quickstart Mode    ...#else                                           //Registered Mode    #define ORG             "vs9qqv"            //Replace with your org    #define DEVICE_TYPE     "PTK-STM32F207"     //    #define AUTH_METHOD     "token"             //    #define AUTH_TOKEN      "X*l5X!(SkF&c3RJVN@"//Replace with your auth-token#endif...
      • Within the IAR-EWARM IDE (As described previously)
        • Make, download and run the code
        • Now the new device is running in Registered mode
      • The running application will connect to the IBM Watson IoT Platform service and start sending data periodically, the touch information will also be sent each time you touch the LCD screen of PTK-STM32F207. But the drawing may not appeared since the application of server side is not built and deployed yet.
    4. Modifying the Node-RED flow for the white board application. Finally, we have to add collaborative features to the application
      • Lets go back to our Node-RED flow editor by clicking the application URL.
      • Setup input node to subscribe the incoming touch event
        • Creating a new ibmiot input node to subscribe touch event
        • Setup the properties as shown below
      • Setup a function node to retrieve the x-y event of drawing request
        • Creating a new function node to get touch information
        • Double click on the function node to open the javascript editor. Replace the existing code with the following :
          var out_msg = {    "payload" : JSON.stringify(msg.payload)};return out_msg;
      • Setup output nodes to publish the commands of drawing actions
        • Creating two ibmiot output nodes and setup properties as follows.
          The device ID must be setup properly. The ID info is shown on LCD screen of PTK-STM32F207.

          Note :
          We should create ibmiot output node for eacah one of joined devices
      • Wiring them together as shown below and deploying the application.
    5. Enjoy the game

Expected Outcome

With this recipe you can ...


* Check if you have the right ingredient before continuing.
* Get your device ready for working with IBM IoTF.
* Connecting your device to IoTF Quickstart server.
* Viewing the sensor data coming from your device with IoTF Quickstart site.
* Use IBM Bluemix to create applications to inspect your data.
* Use IBM Bluemix to create applications to control your device.
* Use IBM Bluemix to create a collaborative application for two devices to draw on a shared canvas in real time.

Join The Discussion