Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nikoshet/iot-rpi-sensehat-with-android-monitoring
This repository provides information and code for using an Android App, a Desktop App and a Raspberry Pi with a Sense HAT with Azure IoT Hub and IBM IoT Foundation, as well as providing a REST API for Third Party Providers
https://github.com/nikoshet/iot-rpi-sensehat-with-android-monitoring
android azure csharp ibm-iot-foundation iot python raspberry-pi rest-api
Last synced: 6 days ago
JSON representation
This repository provides information and code for using an Android App, a Desktop App and a Raspberry Pi with a Sense HAT with Azure IoT Hub and IBM IoT Foundation, as well as providing a REST API for Third Party Providers
- Host: GitHub
- URL: https://github.com/nikoshet/iot-rpi-sensehat-with-android-monitoring
- Owner: nikoshet
- License: gpl-3.0
- Created: 2018-06-17T11:38:26.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-18T13:10:40.000Z (over 5 years ago)
- Last Synced: 2024-04-19T19:08:01.328Z (7 months ago)
- Topics: android, azure, csharp, ibm-iot-foundation, iot, python, raspberry-pi, rest-api
- Language: Java
- Homepage:
- Size: 50.6 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# IoT-RPi-senseHAT-with-Android-monitoring
The goal of this project was the connection and monitoring of a Raspberry Pi with the Azure IoT Hub, the modeling of an Android Application and connection with the IBM IoT Foundation, the design of a specific architecture of the mutual cooperation of the above with a Desktop Application, as well as the development of a REST API for the connection with third party providers.
## Getting Started
These instructions will try to help you build the project on your own.I will try to be quick and simple.
### Equipment Used
```
Raspberry Pi 3
Sense Hat board
Android Phone
Laptop
```
### Libraries Used
```
• For Desktop Application:
IBMWIoTP, Microsoft.ServiceBus, Newtonsoft.Json, Nancy, southbound_API
• For Android Application
org.eclipse.paho.android.service.jar, org.eclipse.paho.client.mqttv3.jar
• For Device(Rpi-SenseHat)
iothub_client, sense_hat, azure IoT Hub SDK for Python
```### Characteristics of the System
#### Device (RPi - Sense Hat)
```
• Used: Temperature and Humidity Sensors,
8×8 LED matrix
• User sets Temperature and Humidity
ALERT thresholds
• User sets Message Timespan for Report on
Azure IoT Hub
```#### Console Application
```
• Reads Device to Azure Cloud Messages
• Publishes Commands to Smartphone based on sensor Alerts
• Reads Smartphone Report Event and sends feedback
• Supports a specific REST API for Third Party Libraries
(with Authorization Key)
```#### Android Application
```
• Reads Commands from Console App and actuates based on sensor Alerts:
• On Temperature Alert:
• Flash Light On/Off
• Vibration
• On Humidity Alert:
• Sound Alert
• Sends Report Request to Console App for Sensor Values
```### Configuring Device
**Connection of Sense HAT with Raspberry Pi**
* First make sure you install the Raspbian operating system for RPi, and enable SSH and I2C
* Push the Sense HAT carefully onto the pins of your Raspberry Pi, and secure it with the remaining screws
* Connect to your RPi (via PuTTy or LCD Screen) and type the following commands:
```
sudo apt-get update
sudo apt-get install sense-hat
sudo reboot
```
**Connection with Azure IoT Hub**
* Create an IoT hub
* Register a device in the IoT hub for your device
* Run the application on Pi
* Clone the application by running the following command:
```
cd ~
git clone https://github.com/nikoshet/IoT-RPi-senseHAT-with-Androidmonitoring/iot-hub-python-raspberrypi-client-app.git
```
* Open the config file by running the following commands:
```
cd iot-hub-python-raspberrypi-client-app
nano config.py
```
In the config.py file you can set Temperature and Humidity ALERT thresholds, and Message Timespan for Report on Azure IoT Hub.
* Build the sample application by running the following command:
```
sudo chmod u+x setup.sh
sudo ./setup.sh
```
* Run the sample application by running the following command:
```
python app.py ''
```
Now your device sends temperature and humidity data on the IoT Hub.### Configuring Android App
**Connection with IBM IoT Watson Platform**If you want to connect your smartphone with the IBMIoT Watson Platform the only thing you have to do , is to create an IBM account , and visit this uri
https://your_org_id.internetofthings.ibmcloud.com/dashboard/#/boards/
(replace org_id with your account org_id)
Follow the next steps:
* Create a Device , to get device_id and useful keys for the connection ( the only permission if you have android smartphone , is to modify the Device Type as “Android” , restrictively. )
* If you want to create a Desktop Application, or to use the one developed , so as to send commands to your smartphone , you have also to create an app , with role → Backend Trusted Application ( the role you will choose is important!) , in order to connect as an ApplicationClient and interact with your smartphone device.
**To Configure the App**There are 2 ways to do that:
* 1:
* Clone the application by running the following command (or Download):
```
git clone https://github.com/nikoshet/IoT-RPi-senseHAT-with-Androidmonitoring/android.git
```
This android app can connect to Watson IoTP with custom modification on the source code at class StarterFragment.java, and to be more specific to the function handleActivate() (line 148 ) , as shown below (so as to speed up the process of connection with the platform) :
```
app.setDeviceId(""); // your Device Id
app.setOrganization(""); // your Organization Id
app.setAuthToken(""); // your AuthToken
```
* Also with this app you can connect to every Watson IoTP account ( device ) by giving your inputs-keys each time.
After the modification of the code , so as to use the direct connection to your Watson IoTP ,follow the next steps:
* Enable USB Debugging on your smartphone (settings for programmers) , connect it with your desktop / laptop through your USB cable
* Run the android app with the Android Studio, direct to your smartphone.
* 2:
* You can also download from your smartphone and use this app , direct from the apk file ` app-debug.apk ` and connect to every Watson IoTP device by giving your inputs-keys each time.### Configuring Desktop App
* Clone the application by running the following command (or Download):
```
git clone https://github.com/nikoshet/IoT-RPi-senseHAT-with-Androidmonitoring/DesktopApp.git
```
* Open the project on Visual Studio**Connection with Azure IoT Hub and IBM Watson IoTP**
* On the library “CloudInteractions”, on ReadDeviceToAzureMessages.cs set your IoT Hub info as shown below:
```
private static string connectionString = "";
private static string iotHubD2cEndpoint = "messages/events";
private static EventHubClient eventHubClient;
```
* On the library “CloudInteractions”, on IBMMessages.cs set your IBM Watson IoTP info as shown below:
``` private static string orgId = "";
private static string appId = "";
private static string apiKey = "";
private static string authToken = "";
private static string deviceType = "";
private static string deviceId = "";
private static string format = "json" ;
static ApplicationClient applicationClient = new ApplicationClient(orgId, appId, apiKey, authToken);
```
**For the REST API**
Uris used:
```
/getstate/{deviceId}/temperature
/getstate/{deviceId}/humidity
/getstate/{deviceId}/temperature/all
/getstate/{deviceId}/humidity/all
/get/devices
```## Miscellaneous
#### Sense HAT
[Here](https://raspberrypi.dk/wp-content/uploads/2015/08/raspberry-pi-sense-hat.pdf) you will find more information about the sense HAT .#### Azure IoT Hub
More info on how to create an IoT Hub and register a device can be found [here](https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-raspberry-pi-kit-pythonget-started) .#### IBM Watson IoT Platform
More info on how to create an IBM account and create a device can be found [here](https://console.bluemix.net/docs/services/IoT/getting-started.html#getting-started-with-iotp) .