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

Was this helpful?

  1. Devices
  2. Bosch XDK 110
  3. Applications
  4. Language XDK Live
  5. MQTT
  6. HomeAssistant

Device

On the device part we need to open our Workbench 3.4.0 open a new Mita Project. Once we have that we could paste the next code:

/**
 * Welcome to XDK LIVE.
 *
 * Not sure what to do now?
 * Check out the "Getting started" guide in the Eclipse help.
 */

package main;
import platforms.xdk110;

// Create a wireless connection named 'wireless'
setup wireless : WLAN {
    ssid = "Totalplay-4B80";
    ipConfiguration = Dhcp();
    authentification = Personal(psk = "pass");
}

// Create a MQTT instance
setup messaging : MQTT {
    transport = wireless;
    url = "mqtt://broker.hivemq.com:1883"; // Try differents brokers iot.eclipse.org, etc. 
    cleanSession = true;
    clientId = "1234";  //Define your userID
    var  button = topic("XDK/RFT/switch",1);    //Define your own topic
    var  temperature = topic("XDK/RFT/temperature/status",1);    //Define your own topic
    var  pressure = topic("XDK/RFT/pressure/status",1);    //Define your own topic
    var  humidity = topic("XDK/RFT/humidity/status",1);    //Define your own topic
}

// When button one is pressed, send text via MQTT
every button_one.pressed {
    messaging.button.write("1"); //Define your message
}

every button_one.released {
    messaging.button.write("0"); //Define your message
}

// Read and transmit the temperature every 5 seconds
every 5 seconds {
    var myTemperature = environment.temperature.read();
    var celsusis = myTemperature / 1000;
    messaging.temperature.write(`${celsusis}`);
}

// Read and transmit the barometric pressure every 10 seconds
every 10 seconds {
    var myPressure = environment.pressure.read();
    messaging.pressure.write(`${myPressure}`);
}

// Read and transmit the barometric humidity every 15 seconds
every 15 seconds {
    var myhumidity = environment.humidity.read();
    messaging.humidity.write(`${myhumidity}`);
}

Then we we flash this project in our device would give us an error, this is produce in a C file.

The issues is that

  1. ButtonOne_OnEvent is defined twice, but it is only required once, technically.

  2. The second implementation of ButtonOne_OnEvent that enqueues the oneReleased1 handler reacts to the event

    BSP_XDK_BUTTON_PRESS instead of BSP_XDK_BUTTON_RELEASE

So open the file SensorButton_one.c and past:

/**
 * Generated by Eclipse Mita.
 * @date 2018-08-16 23:51:10
 */


#include <BCDS_Basics.h>
#include <BSP_BoardType.h>
#include <MitaEvents.h>
#include <BCDS_BSP_Button.h>
#include <BCDS_CmdProcessor.h>
#include <BCDS_Retcode.h>
#include "MitaExceptions.h"

void ButtonOne_OnEvent(uint32_t data)
{
    if(data == BSP_XDK_BUTTON_PRESS) {
        Retcode_T retcode = CmdProcessor_enqueueFromIsr(&Mita_EventQueue, HandleEveryButton_onePressed1, NULL, data);
        if(retcode != RETCODE_OK)
        {
            Retcode_raiseErrorFromIsr(retcode);
        }
    }

    if(data == BSP_XDK_BUTTON_RELEASE) {
            Retcode_T retcode = CmdProcessor_enqueueFromIsr(&Mita_EventQueue, HandleEveryButton_oneReleased1, NULL, data);
            if(retcode != RETCODE_OK)
            {
                Retcode_raiseErrorFromIsr(retcode);
            }
        }
}


Retcode_T SensorButton_one_Setup(void)
{
    return BSP_Button_Connect();

    return NO_EXCEPTION;
}

Retcode_T SensorButton_one_Enable(void)
{
    Retcode_T retcode = NO_EXCEPTION;

    retcode = BSP_Button_Enable((uint32_t) BSP_XDK_BUTTON_1, ButtonOne_OnEvent);
    if(retcode != NO_EXCEPTION) return retcode;

    retcode = BSP_Button_Enable((uint32_t) BSP_XDK_BUTTON_1, ButtonOne_OnEvent);
    if(retcode != NO_EXCEPTION) return retcode;


    return NO_EXCEPTION;
}
PreviousServerNextDocker-HomeAssistant

Last updated 5 years ago

Was this helpful?