IOT - Bosch
  • Introduction
  • Devices
    • Bosch XDK 110
      • Introduction
      • Operating System
      • Hardware
        • Sensors
          • Accelerometer
            • C
          • Gyroscope
            • C
            • Mita
          • Magnetometer
            • C
          • Environmental
            • C
            • Mita
          • Ambient Light
            • C
            • Mita
          • Acoustic
            • C
      • Software
        • XDK WorkSpace
          • Structure
          • Debug
          • Supported languages
            • C
              • Static Library (.a)
            • XDK Live - Mita
            • MicroFlo
      • Connectivity
        • Bluetooth Low Energy (BLE)
          • Overview
          • General Info
          • Implementation
            • C
            • XDK Live
        • WI-FI
          • OverView
          • Implementation
            • C
            • XDK Live
        • WI-FI Enterprise
      • Protocols
        • CoAP
          • Overview
          • Implementation -TBD
        • HTTP
          • Overview
          • Structure and Methods
          • Implementation
            • C - Rest
            • C - Post
            • XDK Live
        • HTTPS
          • Overview
          • Implementation TBD
        • LWM2M
          • Overview
          • Implementation TBD
        • MQTT
          • Overview
          • Implementation
            • C
            • XDK Live
        • USB
          • Overview
          • Implementation TBD
      • Data Storage
      • XDK Extension Bus
      • Community
      • Applications
        • Language C
          • HomeAssitant - MQTT
            • Prerequisites
            • Server
            • Device
          • IOTA-MQTT-XDK
            • Prerequisites
            • XDK110
            • Mqtt JSON to MAM
            • SensorHub
            • Demo
        • Language XDK Live
          • MQTT
            • Hello World
            • HomeAssistant
              • Prerequisites
              • Server
              • Device
            • Docker-HomeAssistant
          • HTTP
            • Roku Remote Control
              • Roku API
              • MITA
                • Example
    • Bosch AMRA
    • Bosch GLM 100C
    • Bosch FLEXIDOME IP panoramic
    • Bosch GLM 100C
    • Bosch Rexroth Nexo
    • Bosch Rexroth PRC 7000
    • Bosch RRC / CT100
    • Bosch Rexroth IoT Gateway
  • Bosch IOT Solutions
    • Bosch IOT Projects
      • Smart Home
      • Industry 4.0
      • Smart Cities
      • Connected-mobility
    • Bosch IOT Suite
      • Bosch Analytics
      • Bosch IOT Hub
      • Bosch Iot Permission
      • IoT Remote Manager
      • IoT Rollouts
      • IoT Things
      • Demo TBD **
    • BPM and BRM
  • IOTA
    • Introduction
      • Tangle
      • Glossary
      • Differences with other tech
      • How does iota work
      • Developers
    • Qubic
      • What is Qubic?
      • Target
      • Qubic Protocol
    • Ecosystem
    • Applications
      • Python
      • XDK110
        • Prerequisites
        • XDK110
        • Mqtt JSON to MAM
        • SensorHub
    • Bosch/IOTA
  • ByteBall
    • SmartContract
    • Use Case
      • BoshCoins
Powered by GitBook
On this page
  • Setup
  • Setting up HTTP resources
  • Setting up variable resource-signals
  • Headers
  • Performing Requests

Was this helpful?

  1. Devices
  2. Bosch XDK 110
  3. Protocols
  4. HTTP
  5. Implementation

XDK Live

In Mita, HTTP is defined as a many resource. That means, multiple instances of this resource can exist, and each is given a unique name by the developer. All possible configuration items and signals for the HTTP resource are listed below.

connectivity many HttpRestClient {
    generator "org.eclipse.mita.platform.xdk110.connectivity.RestClientGenerator"
    validator "org.eclipse.mita.platform.xdk110.connectivity.RestClientValidator"

    /**
     * The underlying transport connectivity we use to send the data out. In the future we might also
     * support LoRa here.
     */
    required configuration-item transport : WLAN

    /**
     * The part of the endpoint URL common to all requests, e.g. "http://foobar.com/api/v1"
     */
    required configuration-item endpointBase : string

    /**
     * A custom header which is added to each HTTP request. Example:
     *   "X-Auth: MySecretToken\nX-Version: 1.0"
     */
    configuration-item headerContent : string

    signal resource(endpoint : string, contentType : string = "application/json", writeMethod : HttpMethod = HttpMethod.POST, readMethod : HttpMethod = HttpMethod.GET) : string

}

Setup

HTTP requires a network connection to the destination server, to which the HTTP requests are sent. With the XDK, this network is usually established using Wi-Fi. The following code can be used to create a WLAN resource for use with HTTP:

setup wifi : WLAN {
    connection = Personal;
    ssid = 'mySSID';
    psk = 'myPassword';
}

Setting up HTTP resources

The following code can be used to create an HTTP resource:

setup googleRoot : HttpRestClient {
    transport = wifi;
    endpointBase = 'http://www.google.com:80';
    var root = resource('/');
}

Setting up variable resource-signals

given a backend-api located at www.my-server.com:8080/api, and the resources light and temperature, the following code would initialize an HTTP instance with the specified endpoints as resource-signals:

setup myServer : HttpRestClient {
    transport = wifi;
    endpointBase = 'http://www.my-server/api';
    var light = resource('/light');
  var temperature = resource('/temperature');
}

Every read/write operation on one of the signals will only send HTTP messages to either www.my-server/api/light or www.my-server/api/temperature.

So far, the resource-signals have been initialized with default settings (apart from the endpoint). They have the following optional parameters (and default values):

  • contentType, of type string. This defines the content-type header of the HTTP message. Per default, this is"application/json"

  • writeMethod, of type HttpMethod. This defines which HTTP Method (GET, POST, PUT, DELETE, UPDATE) is used when the signal is accessed using the write method. Per default, this is HttpMethod.POST.

  • readMethod, of type HttpMethod. This defines which HTTP Method (GET, POST, PUT, DELETE, UPDATE) is used when the signal is accessed using the read method. Per default, this is HttpMethod.GET.

Headers

For an HTTP resource, additional headers can be set using the optional configuration-item headerContent. The code below is an example for setting the headers

  • X-Auth: MySecretToken

  • X-Version: 1.0

for messages which are sent using the specifically setup HTTP resource

setup myServer : HttpRestClient {
    transport = wifi;
    endpointBase = 'http://www.my-server/api';
  headerContent = 'X-Auth: MySecretToken\nX-Version: 1.0';
    var light = resource('/light');
}

All headers are insert using a single string, where the headers are separated using the character\n.

Performing Requests

Then the following code will send a POST request (the default write method for resource-signals) to www.my-server/api/helloWorld every 5 seconds, with a JSON payload

every 5 seconds {
  myServer.light.write('{"hello": "world"}');
}

The input must always be a string.

PreviousC - PostNextHTTPS

Last updated 5 years ago

Was this helpful?

All HTTP resources are generally set up with an endpointBase and a transport. The first configuration-item is a full URL, pointing to a desired endpoint base, such as . The configuration-item transport is the Wi-Fi resource, through which the HTTP messages are sent.

http://www.my-backend.com:80