Writing data from Raspberry Pi using OAS REST API

Step 1

To write data into OAS from a Raspberry Pi, you will use the OAS REST API. As a first step, register the HTTP listener with the OAS Service Control Manager under the section labeled “HTML HMI Registration”.

Define the exclusive Node Name and Port Number  that is to be supported. The Node Name should be the registered domain name, IP address, or network node name that all clients will connect to from their browsers. If you are unsure of which node name to use, localhost will work in most cases.

NOTE: Before clicking “Register”, be sure to stop all services. If services are running, the Service Control app will prompt you to stop them.

Step 2

Start up all services, and be sure to include the Framework 4.5 Service as this houses the listener specific to the REST API.

Step 3

Test your API Service from your Raspberry Pi.

You will now ensure that the Raspberry Pi can communicate with OAS via the REST API. In this example, the OAS host is located at, but you will have to replace this with the OAS host node on your network. The base URL you will use to connect to the REST API is http://{{node}}:{{port}}/OASREST/v2. Each operation performed against the REST API will use the specific operation name prepended with the base {{url}}. The first operation to complete is authentication. All sessions with the REST API must be authenticated. You can adjust the {{url}} in the following snippet and test authentication.

For Python 3:

import requests

### base url is http://{{node}}:{{port}}/OASREST/v2/
url = ''  # {{url}}
op = '/authenticate'                           # {{operation}}
payload = "{\"username\":\"\",\"password\":\"\"}"
headers = {'Content-Type':'application/json'}

### Authentication is completed via a POST request
response = requests.request("POST", url+op, data=payload,


If this code is executed without error, the response will include a clientid and token. These will be included in the header for all other operations.

  "messages":["Default credential provided"]

Step 4

Write tag data from Raspberry Pi to OAS.
Now that you’ve established connectivity with the REST API, you can complete a Python script to write data from your device. Here is an example script which detects when a button is pushed, and forwards that data into OAS as a tag.

import requests
import json
import RPi.GPIO as IO            
import time                         

### base url is http://"node":"port"/OASREST/v2
url = ''  # {{url}}
operation = '/authenticate'                  # {{operation}} 

payload = "{\"username\":\"\",\"password\":\"\"}"
headers = {'Content-Type':'application/json'}

### Authentication is required, and is completed with a POST request
response = requests.request("POST", url+operation, data=payload, headers=headers)
json_data = json.loads(response.text)

client_id = json_data["data"]["clientid"]
token = json_data["data"]["token"]

print(client_id, token)

### Setup GPIO board to activate pin 40 as an output
IO.setmode (IO.BOARD)
for i in range(60):

### Finally, turn off all GPIO pins

For further help with the REST API, navigate to http://restapi.openautomationsoftware.com to open the REST API online documentation.

Should I develop a WPF, WinForm, or HTML5 client application?

All support communications over the Internet, so networking is not a deciding factor.

Windows HMI is a good choice if:

  • The customer is not experienced in creating WPF applications but has strong knowledge in building Windows Forms applications and the application is not graphics intensive.
  • The application is for mainly displaying values.
  • The customer wants to use Open Automation Software Controls in an existing Windows Forms Application.
  • The customer wants to write a service to read and write data to Open Automation Software.
  • The customer application will be running on Windows 2000 Professional.

WPF HMI is a good choice if:

  • The customer has no preference and he want to use graphics.
  • The customer would like Lamps, Switches, Shapes, Gauges, Pie Charts, Bar Charts, PID Controls or story boards built into the control library.
  • The customer wants to be using the latest technology.
  • The customer’s application is graphic centered as opposed to mainly a data display.
  • The customer wants to automatically scale his application to the monitor size.
  • The customer wants the ability to Scale, Rotate or Skew object in the application.

Web HMI is a good choice if:

  • If you plan to run the application on a smart phone or non widows operating system.

I am prompted to install the .NET Framework 3.5 during installation?

The .NET Framework 3.5 needs to be enabled.

a) Press “Windows Logo” + “R” keys on the keyboard.

b) Type “appwiz.cpl” in the “Run” command box and press “ENTER”.

c) In the “Programs and Features” window, click on the link “Turn Windows features on or off”.

d) Check if the “.NET Framework 3.5 (includes .NET 2.0 and 3.0)” option is available in it.

e) If yes, then enable it and then click on “OK”.

f) Follow the on-screen instructions to complete the installation and restart the computer, if prompted.