Here you will find sample device scripts for connecting Intel® Arduino/Genuino 101 and DFRobot LCD Keypad Shield to the TechBubble Technologies IoT JumpWay using the Python MQTT Serial Library.
The tutorial allow you to set up an IoT device that can control other IoT devices on the same network using the LCD Keypad Shield and communication via the IoT JumpWay.
In addition to using the LCD Keypad Shield, you can also use a an application or autonomous device communication via the IoT JumpWay to switch the states of the buttons on the keypad.
This project uses three applications:
1. A device application (Arduino) which communicates via serial with a Python Serial/MQTT application.
2. The Python Serial/MQTT application which communicates with the Arduino/Genuio 101 / DFRobot LCD Keypad Shield, and the IoT JumpWay.
3. A Python commands application / device application that can send commands to the device to toggle the state of the buttons. In this tutorial we will use the Intel® Edison Dev Kit LED Python Example which has both a device application and commands application. (Optional)
Python Versions- 2.7 (Python Serial/MQTT application)
- 3.4 or above (Python commands application)
- Arduino/Genuino IDE
- ArduinoJson
- Intel® Arduino/Genuino 101.
- DFRobot LCD Keypad Shield
- An IoT device connected to the TechBubble IoT JumpWay (Optional)
If this is the first time you have used the TechBubble IoT JumpWay in your IoT projects, you will require a developer account and some basics to be set up before you can start creating your IoT devices. Visit the following link and check out the guides that take you through registration and setting up your Location Space, Zones, Devices and Applications (Roughly 5 minutes).
TechBubble Technologies IoT JumpWay Developer Program (BETA) Docs
Adding The Arduino/Genuino Board To Arduino IDE- Tools -> Boards -> Boards Manager
- Search for Curie, or Intel Curie
- Right click on the right hand side of the Curie section and click install to install the latest version
1. For the Python Serial/MQTT application we will need the TechBubble IoT JumpWay Python MQTT Serial Library installed on our PC/laptop/Mac. To Install the library, issue the following command on your chosen device:
$ pip install iot_jumpway_mqtt_serial
2. Install the ArduinoJson library in the Arduino IDE:
Sketch -> Include Library -> Manage Libraries
Search for ArduinoJson
Right click on the right of the ArduinoJson section and click install.
Setting Up Your Intel® Arduino/Genuino 101First of all you need to connect up your DFRobot LCD Keypad Shield to your Intel® Arduino/Genuino 101, place the shield on top of your Arduino as in the image above.
Device Connection Credentials & Actuator Settings- Follow the TechBubble Technologies IoT JumpWay Developer Program (BETA) Location Device Doc (About 1 minute) to set up your main device, if you want to use a second device to trigger autonomous communication, please follow the Intel® Edison Dev Kit LED Python Example tutorial, we will show you how to set up the autonomous communication later in this tutorial. You will need to select the "LCD Keypad (4 Buttons)" actuator whilst setting up your device in the developer console.
- Download the TechBubble IoT JumpWay Python MQTT Serial Library Application and the TechBubble IoT JumpWay Python MQTT Serial Library Config File, you can put them in a folder and name the folder something relevant so that you remember it, you will be able to reuse this application in the future for other tutorials.
- Retrieve your connection credentials by following the link above, and update the config.json file with your new connection credentials.
"IoTJumpWaySettings": {
"SystemLocation": 0,
"SystemZone": 0,
"SystemDeviceID": 0,
"SystemDeviceName" : "Your Device Name",
"SystemDeviceCom" : "Your Device Com Port"
},
"IoTJumpWayMQTTSettings": {
"MQTTUsername": "Your Device MQTT Username",
"MQTTPassword": "Your Device MQTT PASSWORD"
}
- Open up the Intel® Arduino/Genuino 101 DFRobot LCD Control Example and update the following lines with your DFRobot LCD Keypad Shield ID retrieved from the steps above, then upload the sketch to your device:
String JumpWayActuatorID = "1";
- You may also need to alter the debounceWait variable if the buttons trigger multiple times.
int debounceWait = 150;
Execute The Python ProgramAs you have already uploaded your sketch, the program will now be running on your Arduino/Genuino 101. All that is left is to start the Python program with the following line:
$ python NameOfYourSerialApplication.py
Autonomous Communication With Second DeviceEach time you press a button, the device will send actuator data to the TechBubble IoT JumpWay. You can use actuator data values to trigger autonomous communication with other devices you have connected to the IoT JumpWay.
On the device edit page scroll down to the "Create Rules" section under the Actuators / Sensors. Here you can use the dropdown menu to create rules that allow your device to email you, or to autonomously communicate with other devices on its network in the event of status updates, sensor data and warnings.
IoT JumpWay Developer Program (BETA) Location Applications give you the ability to plug in control features for all devices connected to your IoT JumpWay Locations into your own applications.
In this part of the tutorial we will focus on sending commands from our command application to replicate the buttons being pressed on the DFRobot LCD Keypad. This feature means that you could have an Android/iOS/web application and be anywhere in the world and be able to turn on/off whatever device you connected to the keyboard functions in the step above.
Follow the next steps to set up your application:
- We will be using the IoT JumpWay Intel® Edison Dev Kit LED Example Application and the IoT JumpWay Intel® Edison Dev Kit LED Example Config File, you can put them in a folder and name the folder something relevant so that you remember it, you will be able to reuse this application in the future for other tutorials.
- Update the device related configs with the credentials you created from this tutorial. This will mean that the application will no longer be sending control commands to the Edison Dev Kit LED device, but to the Python Serial/MQTT application we created in this tutorial which will, in turn, send the commands to the device and switch the buttons. You need to update the SystemZone, SystemDeviceID, SystemDeviceName and Actuators settings as below, the Actuator settings should match the ones you modified in the Arduino sketch above:
"IoTJumpWaySettings": {
"SystemLocation": 0,
"SystemZone": 0,
"SystemDeviceID": 0,
"SystemDeviceName" : "Your Device Name",
"SystemApplicationID": 0,
"SystemApplicationName" : "Your Application Name"
}
"Actuators": {
"LCD Keypad": {
"ID": 1
}
- Finally you need to update the application itself. At the bottom of the application you will see the following code:
DevKitLedApplication.JumpWayMQTTClient.publishToDeviceChannel(
"Commands",
DevKitLedApplication.configs["IoTJumpWaySettings"]["SystemZone"],
DevKitLedApplication.configs["IoTJumpWaySettings"]["SystemDeviceID"],
{
"Actuator":"LED",
"ActuatorID":DevKitLedApplication.configs["Actuators"]["LED"]["ID"],
"Command":"TOGGLE",
"CommandValue":"ON"
}
)
time.sleep(5)
DevKitLedApplication.JumpWayMQTTClient.publishToDeviceChannel(
"Commands",
DevKitLedApplication.configs["IoTJumpWaySettings"]["SystemZone"],
DevKitLedApplication.configs["IoTJumpWaySettings"]["SystemDeviceID"],
{
"Actuator":"LED",
"ActuatorID":DevKitLedApplication.configs["Actuators"]["LED"]["ID"],
"Command":"TOGGLE",
"CommandValue":"OFF"
}
)
- Change that code to the following:
DevKitLedApplication.JumpWayMQTTClient.publishToDeviceChannel(
"Commands",
DevKitLedApplication.configs["IoTJumpWaySettings"]["SystemZone"],
DevKitLedApplication.configs["IoTJumpWaySettings"]["SystemDeviceID"],
{
"Actuator":"LCD Keypad",
"ActuatorID":DevKitLedApplication.configs["Actuators"]["LCD Keypad"]["ID"],
"Command":"TOGGLE",
"CommandValue":"1"
}
)
time.sleep(5)
DevKitLedApplication.JumpWayMQTTClient.publishToDeviceChannel(
"Commands",
DevKitLedApplication.configs["IoTJumpWaySettings"]["SystemZone"],
DevKitLedApplication.configs["IoTJumpWaySettings"]["SystemDeviceID"],
{
"Actuator":"LCD Keypad",
"ActuatorID":DevKitLedApplication.configs["Actuators"]["LCD Keypad"]["ID"],
"Command":"TOGGLE",
"CommandValue":"2"
}
)
time.sleep(5)
DevKitLedApplication.JumpWayMQTTClient.publishToDeviceChannel(
"Commands",
DevKitLedApplication.configs["IoTJumpWaySettings"]["SystemZone"],
DevKitLedApplication.configs["IoTJumpWaySettings"]["SystemDeviceID"],
{
"Actuator":"LCD Keypad",
"ActuatorID":DevKitLedApplication.configs["Actuators"]["LCD Keypad"]["ID"],
"Command":"TOGGLE",
"CommandValue":"3"
}
)
time.sleep(5)
DevKitLedApplication.JumpWayMQTTClient.publishToDeviceChannel(
"Commands",
DevKitLedApplication.configs["IoTJumpWaySettings"]["SystemZone"],
DevKitLedApplication.configs["IoTJumpWaySettings"]["SystemDeviceID"],
{
"Actuator":"LCD Keypad",
"ActuatorID":DevKitLedApplication.configs["Actuators"]["LCD Keypad"]["ID"],
"Command":"TOGGLE",
"CommandValue":"4"
}
)
- Start up the application with the following command, if the device and the Serial/MQTT applications are running, you will see the output in the Serial/MQTT application and the buttons 1 -4 will be triggered on the device, in turn, communicating with the device you connected up in the autonomous communication section above.
sudo python/python3 Dev-Kit-Led-Application.py
Viewing Your DataYou will be able to access the data in the TechBubble IoT JumpWay Developers Area. Once you have logged into the Developers Area, visit the TechBubble IoT JumpWay Location Devices Page, find your device and then visit the Sensor/Actuator page to view the data sent from your device.
Please feel free to create issues for bugs and general issues you come across whilst using the IoT JumpWay Intel® Arduino/Genuino 101 Examples. You may also use the issues area to ask for general help whilst using the IoT JumpWay Intel® Arduino/Genuino 101 Examples in your IoT projects.
IoT JumpWay Intel® Arduino/Genuino 101 Examples Contributors
Comments