HANA Car v1.0 – Java Webapp
Description | Hyperlink |
---|---|
Overview | HCP IoT HANA Car v1.0 |
Internet of Things configuration | HANA Car v1.0 – Internet of Things configuration |
UI5 Java Webapp | HANA Car v1.0 – Java Webapp |
The Car with raspberry Pi | HANA Car v1.0 – Raspberry Pi |
You could replace the Java Webapp with a UI5 project in the WebIDE by following this blog: Communicate with IoT in your WebIDE project
Before I created a Java webapp I tried to access the IoT service from JavaScript directly. With JavaScript it’s possible to connect to a WebSocket but it’s not possible to use a websocket with bearer authentication. Pushing http messages to the IoT service also didn’t work, then I had cross domain errors. For these reasons I created a Java application with UI5 as webcontent and a Java Servlet to communicate with the IoT service. For this Java Servlet I started from an example on the IoT starter kit:
https://github.com/SAP/iot-starterkit/tree/master/src/apps/java/consumption
User Interface
For the User Interface of the Fiori app I had some help of a friend, Jonas Vanderkelen . Thanks a lot!
The User Interface contains an on/off switch. When it’s on there will appear a joy stick. Moving the joystick will send directions to the Java Servlet. When you move the joystick up it will send the direction. All the directions
Joystick up = “f”
Joystick down = “b”
Joystick left = “l”
Joystick right = “r”
Release joystick = “n”
The joystick will always start by sending foward or backward when the joystick moves up or down (even if its left or right). After that it will send left or right if you hold the joystick that way. This is how I developed the car and can be changed. After some tests this gave the best handling for me 🙂
This is how the UI looks like:
Java Project
The Java project contains a Servlet and a UI5 app:
I reused almost all of the javascript functions from the IoT starter kit but we changed one thing. When sending the message, we changed the method from “http” to “ws” because we’re using the websocket!
I also added our deviceid and messagetype:
I didn’t changed a thing in the Java Servlet.
You can find our project in the attachement. (remove the .txt extension)
Kind regards,
Wouter