Skip to content

IoT Greenhouse Demo Scenario on SAP HCP using RaspberryPI, Python, Java, SAPUI5 and SAP HCP IoT Services

License

Notifications You must be signed in to change notification settings

indaco/saphcpiot-greenhouse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Greenhouse Demo Scenario

NOTE: This document is in DRAFT version, something can be missing or wrong. If you intend to re-create this scenario, you are smart enough to go through without a real step-by-step guide. Anyway, if you find errors, missing steps or typos as well as if you need some help to implement the scenario, feel free to contact me. I really appreciate your help and your feedbacks.

DISCLAIMER: This repository doesn't want to represent the best way to develop on SAP HCP or on RaspberryPi, but it's an attempt to make things work and, it works. Code can be improved in readability, efficiency and design.

This is the repository for a real and complete end-to-end scenario (Greenhouse) built using the SAP Hana Cloud Platform IoT Services (SAP HCP IoT) and a RaspberryPi as a gateway.

The document and the code snippets will provide information on how to quick re-use it, replicate what I built, improve it and extend it.

Greenhouse

The entire Greenhouse scenario is based on two separate applications:

  • greenshouse: Sensor data readings, data transmission via RaspberryPi to SAP HCP and an HTML5 UI/Dashboard developed with SAPUI5 on SAP HCP.

GreenhouseTiles GreenhouseUI1 GreenhouseUI2

  • remotecontroller: Receiving the messages sent to the device. It acts as a controller to switch on/off a lamp, open/close the roof consuming messages sent to the devices.

RemoteController

Shopping list

Here a list of components used to build the scenario:

  • 1 Raspberry Pi B+ or Raspberry Pi 2
  • 1 AM2302 sensor
  • 1 Breadboard
  • 3 leds (Red, Green and Yellow)
  • 3 resistors 330Ω
  • 1 T-Cobbler cable
  • 1 DC 5V Relay module
  • 1 Lamp
  • 1 Continuous Rotation Servo
  • 1 Additional 5V (2000mA) power supply
  • Some jumpers
  • Plexiglass box (W: 50cm H: 25cm)

Prerequisites

In this section you can find a quick list of prerequisites, software and hardware.

Discussing how to connect leds, lamp, servo motor and so on to the RaspberryPi as well as the SAP HCP IoT architecture, features etc. are outside the scope of this document; There are lots of resources available on line.

RaspberryPi

The RaspberryPi acts as a gateway. All the code is written in Python 3 (v. 3.2) and uses some python libs. Take a look to the following links to install all the requirements:

SAP HCP

Getting started with SAP HCP IoT following the step-by-step guides:

  1. Get HANA Cloud Platform Developer Account
  2. Enable Internet of Things Services

How to use it.

In this section you can find steps to replicate the entire scenario. Make sure all the above prerequisites are in place.

1. RaspberryPi

To handle the AM2302 sensor protocol (as well as for of DHT11 and DHT22) will use an utility developed by Adafruit that, among other things, develops and sells many interesting accessories for RaspberryPi.

The sources of Adafruit also contains a library to allow Python code to access the sensor data. Unfortunately, at the moment, the library has not been updated to support Python 3. We will use a class in Python 3, DHTUtils, as a wrapper that implements methods to make the call to the library Adafruit.

First of all, we clone the Adafruit_Python_DHT Github repository and save the code in a Adafruit folder within the home directory of pi user:

cd ~/
mkdir Adafruit && cd $_
git clone https://github.com/adafruit/Adafruit_Python_DHT.git

The, we clone this repository:

cd ~/
git clone https://github.com/indaco/saphcpiot-greenhouse.git

Create a folder to save the code inside it:

cd ~/
mkdir code

Greenhouse App

Move code for the greenhouse app to the right folder:

cd ~/
mv ~/saphcpiot-greenhouse-master/apps/greenhouse/raspberrypi ~/code/greenhouse

and adapt the configs.py with your information.

Remote Controller App

Copy and paste code for the remotecontroller app to the right folder

cd ~/
mv ~/saphcpiot-greenhouse-master/apps/remotecontroller/raspberrypi ~/code/remotecontroller

and adapt the configs.py with your information.

Logging

Both greenhouse and remotecontroller save logs in their respective "logs" folders. You should not see output on the shell.

2. SAP HCP

Getting started with SAP HCP IoT

Use the following documentations as step-by-step guide to:

  1. Create Device Information in Internet of Things Services Cockpit

    • after device and device type creations, it's time to create message types to and from RaspberryPi. Create them as shown in the figures

    MessageFromGreenhouse

    MessageToGreenhouse

  2. [Deploy the Message Management Service (MMS)](Deploy the Message Management Service (MMS)

  3. Consume the messages with HANA XS using XSJS and OData

Greenhouse App

  1. Create a new XS App for the Greenhouse
  2. Copy all the code in ~/saphcpiot-greenhouse/apps/greenhouse/hcp/xs/iotmmsxs to the HANA XS app previously created
  3. Adapt the following files to reflect information from your account and your HANA Schema:
  4. Execute the following SQL Script to grant accesses (refer to Grant Access) documentation
call "HCP"."HCP_GRANT_ROLE_TO_USER"('<user_id>trial.iotmmsxs::iotaccess', '<user_id>');

Remote Controller App

  1. Open the Java project ~/saphcpiot-greenhouse/apps/remotecontroller/hcp/java/it.sapiotlab.greenhouse.remotecontroller with Eclipse
  2. Adapt the index.html file at the bottom of the page (createModel method) to reflect information from your SAP HCP IoT Cookpit
  3. Compile with Maven and Deploy

Start & Stop

Two different scripts are provided to start and stop the applications.

START:

STOP:

Execute them as sudo, e.g.:

cd /home/pi/code/greenhouse/
sudo ./start_greenhouse.sh

Miscellaneous

RaspberryPi Email IP On Boot

To access the RaspberryPi via SSH or other network protocols without a monitor and moving from network to network, we need to know the IP address. The startup_mailer.py utility do exactly this task. It's based on RPi Email IP On Boot Debian documentation by Cody Giles.

Auto-Start&Stop

Crontab tasks are used to automatically start and stop the scenario.

Application Wake-Up Sleep Days
Greenhouse 8:00 AM 8:00 PM Monday - Friday
RemoteController 8:05 AM 7:55 PM Monday - Friday

Run crontab -e and paste the following entries:

# Greenhouse
0 8 * * 1-5 /home/pi/code/greenhouse/start_greenhouse.sh > /tmp/start_greenhouse.log
0 22 * * 1-5 /home/pi/code/greenhouse/stop_greenhouse.sh > /tmp/stop_greenhouse.log
# Remote Controller
5  8  * * 1-5 /home/pi/code/remotecontroller/start_remotecontroller.sh > /tmp/start_remotecontroller.log
55 19 * * 1-5  /home/pi/code/remotecontroller/stop_remotecontroller.sh > /tmp/stop_remotecontroller.log

You can find the cron-file.txt for both the applications.

Further Resources

License

All the code is released under Creative Commons CC0 1.0 Universal (CC0 1.0) license

About

IoT Greenhouse Demo Scenario on SAP HCP using RaspberryPI, Python, Java, SAPUI5 and SAP HCP IoT Services

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published