SAPUI5 Data Binding Examples

This post lists several examples of simple and more complex data binding use-cases in SAP’s web technology SAPUI5.

Select from Array of Objects

SAPUI5 sap.m.SelectThis sample code feeds a sap.m.Select element from an array of objects. The displayed text is an attribute of the object, in this example called name . On selection change the third snippet acquires a reference to the object that is bound to the newly selected item for further processing of other attributes, e.g. value .

<Select id="selectId" items="{modelPath>/arrayName}" change="onSelectionChanged">
  <core:ListItem key="{modelPath>name}" text="{modelPath>name}" />
</Select>
// model
var model = new sap.ui.model.json.JSONModel();
model.setData({ 
  arrayName: [
    {
      name: "First Item",
      value: 100
    },
    {
      name: "Second Item",
      value: 123
    }
  ]
});

this.getView().setModel(model, "modelPath");

Getting the value attribute when the onSelectionChanged event is fired.

onSelectionChanged: function(oEventArgs) {
  var selectedItem = oEventArgs.getSource().getSelectedItem();
  var bindingContext = selectedItem.getBindingContext("modelPath");
  
  // get binding object (reference to an object of the original array)
  var arrayObject = context.oModel.getProperty(context.sPath).data;
  var value = arrayObject.value;
}

Continue reading “SAPUI5 Data Binding Examples”

Arduino 433 MHz Wireless Module

433 MHz Wireless Module
The 433 MHz wireless module. Transmitter: top-left. Receiver: bottom-right.

This post provides a quick reference for the 433 MHz wireless module, which is widely used in combination with the Arduino. The VirtualWire library is one possible way of utilizing the module.

Before you get started make sure you have attached antennas to both, transmitter and receiver. The wavelength can be calculated using the following formula.

$$\lambda = \frac{c}{f}$$

For $f=433\text{ MHz}$ this leads to $\lambda = 0.6923\text{ m}$.

Wiring

Transmitter

VCC 3.5 – 12 V Power supply
ATAD Arduino pin 12 Serial data
GND GND Ground (0 V)

Continue reading “Arduino 433 MHz Wireless Module”

Typing Speed, Point Set Creator, and Poker Hands

This post summarises what I’ve been coding during the last week. That’s two new web tools for my Online-Tools webpage called Typing Speed and Point Set Creator, and in addition to that a mobile-first Poker Hands website.

Typing Speed

This web tool lets you determine how quickly you can type a character sequence of your choice. This could be for instance your name, email address, password (don’t worry, it won’t be transferred for further analysis), or just something like “hello there”, “hi”, or “abcdefg”. The fact that you can choose what you type distinguishes this page from many other typing game sites that are available.

Note that the tool counts keystrokes not correctly written characters. So you want to make sure you type things correctly. The tool can be found at tools.timodenk.com/typing-speed. The corresponding commit on GitHub: Simsso/Online-Tools

Type something in the input field, to see how fast you are.
Type something in the input field, to see how fast you are.

Point Set Creator

The second tool was created because I needed a set of data points to test clustering algorithms. It basically allows the user to click on a canvas in order to add a new point, to eventually get a list of all points in a usable format. This is especially helpful when a bulk of data points is needed in a roughly predefined shape.
Continue reading “Typing Speed, Point Set Creator, and Poker Hands”

Smart Home Security Camera

This post explains the technical background of the security camera system, shown in the following movie. The post will answer the questions: How to detect a thief, how to take a photo, how to get notifications on your phone, and whether the system would work in reality.

For cutting the movie I made use of iMovie.
iMovie was used for editing.

Links and Quick Facts

The source code is not publicly accessible. For the development I used this configuration.
Buy the system for your home / shed / garage.
Movie background music: LCMC music
Additional information about me.

Technical Details

How to Detect a Thief?

In order to detect a thief I made use of an acceleration sensor that I placed at the apartment’s door. The sensor listens for significant changes in the measured x-acceleration. This technique was so precise, that even the slightest knock triggered the motion detection.

bool motionDetected(float tolerance) {
  readMPU6050SensorData(&mpu6050Data, MPU_addr);
  int16_t accX = mpu6050Data.acceleration.x;
  return (accX > boundaries.max + delta * tolerance || 
    accX < boundaries.min - delta * tolerance);
}

Continue reading “Smart Home Security Camera”

Ambient Light (Arduino Project)

This blog post explains the technical details of my Ambient Light project. If you don’t know what this project is about, watch the following video first:


Video summary: Sometimes a screen is just a light spot in a dark room. To make the entire scenery more appealing, I created my own, Arduino-powered ambient light. A PC software (written in C#) reads color information of the screen, performs some processing and forwards the color information to an Arduino, which is connected via USB. The microcontroller then regulates one or more RGB LEDs.

System Architecture

Ambient Light System Architecture

  1. The C# Program starts two threads: UI thread and “Screen color reading” thread
  2. The “Screen color reading” thread samples the average screen color.
  3. The average screen color’s saturation is being increased by a user-defined factor.
  4. The RGB value is being transmitted through the PC’s Serial Port.
  5. The Serial Port forwards the data to the a Microcontroller (e.g. an Arduino) via USB.
  6. The Microcontroller makes one or more RGB LEDs shine in the received color.

Continue reading “Ambient Light (Arduino Project)”

Install Node SerialPort on Raspberry Pi

Since I had a lot of trouble installing the npm package serialport on my Raspberry Pi B Rev 1 (and Rev 3), I want to share how it eventually worked.

When installing serialport I ran into a lot of errors.
When trying to install using npm install serialport you might see those errors.

Enable serial port usage by adding  enable_uart=1 to the file /boot/config.txt.

If the normal  npm install serialport doesn’t work for you try the following.

Install Node 6.x

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs 
sudo apt-get install -y build-essential

Install node-gyp and node-pre-gyp globally Continue reading “Install Node SerialPort on Raspberry Pi”

Die drei ??? Telegram Bot

Since the publisher Europa uploads new Die drei ??? episodes on Spotify quite frequently, I have been wanting to get an update every time they upload something new. For me the most convenient way to be notified is to get a message on my smartphone. The free messenger Telegram is predestinated for that task because of its open API and bot capabilities.

A bot is like a Telegram user. The only difference: You are not chatting with a person but a program that is running on a server somewhere else. For my bot that is a Node.js script, being executed on my Raspberry Pi.

How does it Work?

To get updates you have to search for the bot on Telegram (the name is @DieDreiFragezeichenBot) or click on that link: @DieDreiFragezeichenBot

Then you have to subscribe by writing /start. The bot will respond with a success message. Now you are on a list of subscribed clients and the next time the bot detects new episodes, you will get an update pretty much like that:

Once there are new episodes you'll get an instant update.
Once there are new episodes you will get an instant update.
The bot just looks like a normal chat partner.
The bot just looks like a normal chat partner.

Continue reading “Die drei ??? Telegram Bot”

ABAP Objects Quick Reference

This is the second (and final) part of a quick reference for the programming language ABAP. Extending the first part, this one is primarily focusing on ABAP’s object oriented programming features, like classes, OOP-exceptions, and inheritance.

The first part can be found here: ABAP Quick Reference

Encapsulation using function groups
FUNCTION-POOL s_person.

* age is a global variable in the function-pool
DATA: age TYPE i.

FUNCTION inc_age.
  ADD 1 to age.
ENDFUNCTION.
Local class definition
REPORT ... .
DATA: ...
...
CLASS lcl_classname DEFINITION.
  " class definition
  ...
ENDCLASS.

CLASS lcl_classname IMPLEMENTATION.
  " class implementation
  ...
ENDCLASS.

* report content

CREATE OBJECT ...
Public and private attributes

ABAP has the visibilities publicprivate, and protected.

CLASS lcl_classname DEFINITION.

  PUBLIC SECTION.
    DATA: mv_publicvar TYPE i.

  PRIVATE SECTION.
    DATA: mv_privatevar1 TYPE i READ-ONLY, " const
          mv_privatevar2 LIKE mv_privatevar1.
    
    " static variable
    CLASS-DATA: gv_n_o_staticvar TYPE i.

ENDCLASS.

Continue reading “ABAP Objects Quick Reference”

ABAP Quick Reference

This is the first of two posts, providing a quick reference for ABAP developers. It primarily consists of code examples and doesn’t include major object oriented programming features, introduced in newer language versions.

The second part of this series, targeting OOP related topics, can be found here: ABAP Objects Quick Reference

ABAP (Advanced Business Application Programming) is a high-level programming language created by the German software company SAP SE. It is currently positioned, alongside Java, as the language for programming the SAP Application Server, which is part of the NetWeaver platform for building business applications.
Wikipedia ABAP article

Basic program structure
PARAMETERS pa_num TYPE i.

* declare a variable
DATA gv_output TYPE i.

* assign value from pa_num to gv_output
MOVE pa_num TO gv_output.

WRITE: 'Input value', gv_output.

NEW-LINE. " this is an inline comment

WRITE 'Done'.
Types

Standardtypes

  • I: Integer (4 bytes)
  • F: Floating point number (8 bytes)
  • D: Date JJJJMMTT (8 bytes)
  • T: Time HHMMSS (6 bytes)
  • STRING: String of dynamic length
  • XSTRING: Hexadecimal string
  • DECFLOAT16: Decimal floating point (8 bytes)
  • DECFLOAT34: Decimal floating point (16 bytes)
  • The common data type “boolean” doesn’t exist in ABAP. Use a custom solution (e.g. X for true and (whitespace) for false)

Incomplete data types

  • C: Character array of fixed length
  • N: Numerical character of fixed length
  • X: Hexadecimal byte array of fixed length
  • P: Packed number of fixed length (and optionally number of digits)
Type definition
TYPES gty_default_float TYPE p LENGTH 16 DECIMALS 2.

Continue reading “ABAP Quick Reference”