Sample Bosch sensor MQTT Simulation

  1. Table of Contents
  2. Overview
  3. This update package ships a sample MQTT simulation for a Bosch sensor, as detailed in this Blog post. <.

  4. Prerequisites
  5. To run this simulation, you must have installed the following optional modules as documented in the online documentation:

    • MQTT

  6. Usage
  7. To run the simulation, invoke the File->Open menu from the MIMICView GUI, and select the mqtt-bosch1.cfg file.

    • Select agent 1 and change its IP address, if necessary. You MUST configure your MQTT broker address in the MQTT tab of the Edit->Configure->All... dialog.

    • Start agent 1 using the Agent->Start menu item.

    • Use MIMICView Edit->Copy and Edit->Paste to duplicate agents.

    This simulation will generate a payload every 5 seconds as detailed in this video and as shown in this mosquitto subscriber output:

    % ./mosquitto_sub -h 192.9.200.14 -t BCDS/#a -v
    BCDS/XDK/single/20:19:AB:F4:00:01/out/stream {"sn":"xx:xx:xx:xx:xx:xx","data":{
    "acc":{"x":26,"y":32,"z":1012,"unit":"mG"},"gyro":{"x":1220,"y":-6835,"z":-2319,"unit":"mdeg/s"},
    "mag":{"x":40,"y":1,"z":-4,"unit":"uT"},"light":{"value":227520,"unit":"mLux"},
    "temp":{"value":30880,"unit":"mCelsius"},"pressure":{"value":98897,"unit":"Pascal"},
    "humidity":{"value":39,"unit":"%rh"}}}
    BCDS/XDK/single/20:19:AB:F4:00:01/out/stream {"sn":"xx:xx:xx:xx:xx:xx","data":{
    "acc":{"x":26,"y":32,"z":1012,"unit":"mG"},"gyro":{"x":1220,"y":-6835,"z":-2319,"unit":"mdeg/s"},
    "mag":{"x":40,"y":1,"z":-4,"unit":"uT"},"light":{"value":227520,"unit":"mLux"},
    "temp":{"value":30880,"unit":"mCelsius"},"pressure":{"value":98897,"unit":"Pascal"},
    "humidity":{"value":39,"unit":"%rh"}}}
    

    Notice that sn contains the constant xx:xx:xx:xx:xx:xx. Let's change the simulation to put in a proper serial number:

    1. Stop the agent with Agent -> Stop . Once it is red, then

    2. configure a new Config File for the agent in the MQTT tab of the Edit->Configure->All... dialog. First, click on Browse... and select the mqtt-bosch.cfg, file. Then click Edit....

    3. the MIMIC IDE appears with the contents of the mqtt-bosch.cfg config file. This is where the MQTT simulation is defined, as detailed in the MQTT online documentation.

    4. Since we don't want to touch it, click File -> Save As... and save as a new file, eg. my-bosch.cfg.

    5. The IDE Editor now shows the new my-bosch.cfg file. We can change it and save it. Notice, the folder for the file has changed to your MIMIC private data area folder as detailed in the QuickStart.

    6. You can change the frequency by editing the interval field, or the topic by editing the topic field. Remember to File -> Save if you change anything.

    7. To change the JSON, we need to first copy/paste the JSON file. You can do that from any command shell, but we will do it in the IDE next.

    8. Use File -> Open... in the IDE to open the scripts/mqtt/mqtt-bosch.json file. For that, you need to navigate from the current folder, which is most likely the bin/ folder, since that is where the IDE is running. Press the up arrow next to the folder name to go up one folder, then into scripts and mqtt.

    9. To see all files in this folder, you need to select All Files (*) in the Files of type selection list. Once you do that, you can select the mqtt-bosch.json file.

    10. Again, once it is edited, we don't want to touch it, so we need to use File -> Save As... and save the file as a different name, eg. my-bosch.json.

    11. Now you can edit the my-bosch.json file, and change at will.

    12. To parameterize the serial number of the simulation, change the line
      "sn": "xx:xx:xx:xx:xx:xx",
      
      to

      "sn": {
              "MIMIC_action" : "store_get(SN)",
              "MIMIC_json_type" : "string"
      },
      

      Once you do, and start the agent, the payload is now something like

      % ./mosquitto_sub -h 192.9.200.14 -t BCDS/# -v
      BCDS/XDK/single/20:19:AB:F4:00:01/out/stream {"sn":"20:19:AB:F4:00:01","data":{
      "acc":{"x":26,"y":32,"z":1012,"unit":"mG"},"gyro":{"x":1220,"y":-6835,"z":-2319,"unit":"mdeg/s"},
      "mag":{"x":40,"y":1,"z":-4,"unit":"uT"},"light":{"value":227520,"unit":"mLux"},
      "temp":{"value":30880,"unit":"mCelsius"},"pressure":{"value":98897,"unit":"Pascal"},
      "humidity":{"value":39,"unit":"%rh"}}}
      BCDS/XDK/single/20:19:AB:F4:00:01/out/stream {"sn":"20:19:AB:F4:00:01","data":{
      "acc":{"x":26,"y":32,"z":1012,"unit":"mG"},"gyro":{"x":1220,"y":-6835,"z":-2319,"unit":"mdeg/s"},
      "mag":{"x":40,"y":1,"z":-4,"unit":"uT"},"light":{"value":227520,"unit":"mLux"},
      "temp":{"value":30880,"unit":"mCelsius"},"pressure":{"value":98897,"unit":"Pascal"},
      "humidity":{"value":39,"unit":"%rh"}}}
      
      

      Notice that sn now is not the constant xx:xx:xx:xx:xx:xx any more because the value of is retrieved from the Agent Store. You can make this variable unique for every agent that is running.

    This process is seen in this Youtube video.

    The mqtt-bosch3.cfg file is already setup to make the serial number unique for every sensor, and temp changeable in real-time via the Agent Store.