C/C++編譯除錯及UML
RTOS 及 Middleware
MCU 及 Cortex M系統
高階 ARM JTAG ICE
穿戴式GUI設計 emWin
APP雲端IoT開發/合作
軟體開發測試管理
無線感測積木
大巨量資料高效傳輸
其他
IBM IoT Foundation
回上一頁
 
 
 
 
 

> >

  Microtime PTK System with STM32F207 Adopted

Use the PTK prototyping environment, available for a wide range of Cortex-M embedded processors adopted, to connect to the IBM Internet of Things Foundation , visualize the data in real time and create applications using the connected devices.

    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.
Ingredients
Hardware Requirements
  PTK-STM32F207 [ Part-Number : 80K-F207IT ]
(http://www.microtime.com.tw)
The platform contains the following sensors :
  • Touch screen
  • Accelerometer
  • Temperature sensor
  • Light sensor
  • Potentiometer
  • Joysticks

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 :\Microtime\PTK
  • 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 source code of uC/OS-II or uC/OS-III and Fix-Up ePBB with the loaded 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 delivering)
    • Install debug probe (JTAG-ICE) for code burning and debugging
  • Connect device to a network with Internet access using an ethernet cable

Connect (Quickstart)
Internet of Things Foundation Quickstart connection
(1)

 
Open the following project workspace within IAR-EWARM IDE
:\Microtime\PTK\ePBB\Applications\Projects\PTK-STM32F207\EWARM-V6\OS_uC
OS-II\base_MQTT\demo.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 :
You should ignore the message "Response timed out."
(4) Take note and mark the IP that was resolved as MQTT_HOST_IP.
(5)
 
To allocate a static ip for PTK-STM32F207 and mark the IP that was allocated as
APP_TCPIP_CFG_IF_IP_ADDR_STR
(6)




 
Expand the project folder, open the following config file
:\Microtime\PTK\ePBB\Applications\Projects\PTK-STM32F207\EWARM-V6\OS_uC
OS-II\src\MQTT_cfg.h and modify the configuration details accordingly.
Note :
The IPs 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
            ...
            //Change the following settings according to what you resolved
            #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"
            ...
            #define MQTT_HOST_IP                    "184.172.124.189"
            ...
            #define ORG "quickstart"
            ...
        -------------------------------------------------------------------
(7) Within the IAR-EWARM IDE
 
  • Select "MQTT" configuration
  • Make the project (Ensure 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.

Visualize(Quickstart)
Real-time visualization of device data can be achieved by visiting the
IBM IoT Foundation 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) To view the data, simply type in the Device ID of PTK-STM32F207
                    

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 Foundation"
  • 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)
 
Link your application and device
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. (It 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 accept 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
    • In normal condition the "Light" message will be seen on debug pane
    • Blocking the light that may inject to the light sensor, this causes message "Dark" be showed on debug pane
      Note :
      The light sensor (U3) is located on lower left corner of PTK-STM32F207
 
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 Internet of Things Foundation 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 IoT Foundation 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 Internet of Things Foundation organisation.
  • Select the Devices tab
  • Select Add Device
  • Enter a device type, device ID and 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 will 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 .messaging.internetofthings.ibmcloud.com

    Note:
    Replace with the org field, vs9qqv, you got in step-2.
  • Take note and mark the IP that was resolved as MQTT_HOST_IP
  • Again, open the MQTT_cfg.h file and make the following changes
         ----------------------------------------------------------------------
             ...
             #define MQTT_HOST_IP "23.246.232.210"         //replace with what you got
             ...
             #define ORG "vs9qqv"                                        //replace with what you got
             #define DEVICE_TYPE "PTK-STM32F207"             //
             #define AUTH_METHOD "token"                          //
             #define AUTH_TOKEN "8MSW*8RMm@BkG9U3!p"     //replace with what you got
             ...
     ----------------------------------------------------------------------   
 
  • 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 organization you just created in the IBM IoT Foundation service and start sending data periodically
(4) Link your application and 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
  • n 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 to 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 IoT Foundation. The sample program loaded on our device can accept commands for beeping control.
 
  • You can try this out by writing applications which connect to the IoT Foundation 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.
 
 
  • If everything is okay, 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 our 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.
 
The white board application (Registered) :
In this section, we build a collaborative application (Whiteboard) with two PTK devices and IBM IoT Foundation 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 listed 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 listed in section "Visualize (Quickstart)" and check if the data can be seen on the cloud.
(2) Register the new setup device to your IoT Foundation organisation
 
  • Entering Devices tab of IoT Foundation dashboard
  • 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.
    It will be something 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 .messaging.internetofthings.ibmcloud.com
  • Take note and mark the IP that was resolved as MQTT_HOST_IP
  • Again, open the MQTT_cfg.h file and make the following changes
 
---------------------------------------------------------------
    
   
    
    
...
#define MQTT_HOST_IP "23.246.232.210"  
...
#define ORG "vs9qqv"                   
#define DEVICE_TYPE "PTK-STM32F207"    
#define AUTH_METHOD "token"            
#define AUTH_TOKEN "X*l5X!(SkF&c3RJVN@"
...
 
//replace with what you got
 
//replace with what you got
//
//
//replace with what you got
---------------------------------------------------------------
 
  • 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 IoT Foundation 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 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 command 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
 
 

回上頁

 
 
 
   

About us │ Product │ News │ Training │ Download │ Support │ Contact │ Home