GithubHelp home page GithubHelp logo

fiware / tutorials.iot-over-mqtt Goto Github PK

View Code? Open in Web Editor NEW
62.0 11.0 44.0 1.24 MB

:orange_book: FIWARE 203: Provisioning Ultralight with an alternative transport: IoT over MQTT

Home Page: https://fiware-iotagent-ul.rtfd.io

License: MIT License

Shell 100.00%
tutorial fiware fiware-iot-agents ultralight mqtt mqtt-broker iot iot-agent

tutorials.iot-over-mqtt's Introduction

FIWARE Banner

FIWARE IoT Agents License: MIT Support badge UltraLight 2.0

This tutorial uses introduces the use of the MQTT protocol across IoT devices connecting to FIWARE. The UltraLight 2.0 IoT Agent created in the previous tutorial is reconfigured to communicate with a set of dummy IoT devices using MQTT via a Mosquitto message broker

The tutorial uses cUrl commands throughout, but is also available as Postman documentation.

Start-Up

NGSI-v2 Smart Supermarket

NGSI-v2 offers JSON based interoperability used in individual Smart Systems. To run this tutorial with NGSI-v2, use the NGSI-v2 branch.

git clone https://github.com/FIWARE/tutorials.IoT-over-MQTT.git
cd tutorials.IoT-over-MQTT
git checkout NGSI-v2

./services create
./services start
NGSI v2 ๐Ÿ“š Documentation Postman Collection

License

MIT ยฉ 2018-2024 FIWARE Foundation e.V.

tutorials.iot-over-mqtt's People

Contributors

actions-user avatar falkorichter avatar fisuda avatar jason-fox avatar sblechmann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tutorials.iot-over-mqtt's Issues

Lamp already exists

When you want to provision the smart lamp in request 10 it already exists.

I deleted it manually and then provisioned it normally.

How do I add seven levels in my topic

I have a message broker deployed in my home which listens to multiple sensors at topic /xxxx/xxxx/xxxx/xxxx/xxxx/xxxx/xxxx. I am trying to connect the broker to iot-agent, but from fiware guide I can see the topic should be of format api-key/device-id/attrs. Is it possible to modify this topic structure to use my original seven level topic? I am new to this whole fiware setup, any help would be appreciated, thanks!

Tutorial with own MQTT-Broker - PLS Help

Hi, I am fairly new to Fiware and I am interested in using an IoT-Agent to collect sensor data from an existing MQTT broker. I am trying to make things work by using this tutorial as a starting point and changing some environmentals in the docker-compose.yml.

The MQTT-broker I'd like to connect to uses root CA, mqtts and user credentials to login. My docker-compose looks like this:

iot-agent:
image: fiware/iotagent-ul:1.7.0
hostname: iot-agent
container_name: fiware-iot-agent
depends_on:
- mongo-db
- mosquitto
networks:
- default
expose:
- "4041"
ports:
- "4041:4041"
environment:
- IOTA_CB_HOST=orion # name of the context broker to update context
- IOTA_CB_PORT=1026 # port the context broker listens on to update context
- IOTA_NORTH_PORT=4041
- IOTA_REGISTRY_TYPE=mongodb #Whether to hold IoT device info in memory or in a database
- IOTA_LOG_LEVEL=DEBUG # The log level of the IoT Agent
- IOTA_TIMESTAMP=true # Supply timestamp information with each measurement
- IOTA_CB_NGSI_VERSION=v2 # use NGSIv2 when sending updates for active attributes
- IOTA_AUTOCAST=true # Ensure Ultralight number values are read as numbers not strings
- IOTA_MONGO_HOST=mongo-db # The host name of MongoDB
- IOTA_MONGO_PORT=27017 # The port mongoDB is listening on
- IOTA_MONGO_DB=iotagentul # The name of the database used in mongoDB
- IOTA_MQTT_HOST=hostaddress.de # The host name of the MQTT Broker
- IOTA_MQTT_PORT=8883 # The port the MQTT Broker is listening on to receive topics
- IOTA_MQTT_PROTOCOL=mqtts
- IOTA_MQTT_USERNAME=Mqtt-Account
- IOTA_MQTT_PASSWORD=Mqtt-Password

- IOTA_PROVIDER_URL=http://iot-agent:4041
healthcheck:
test: curl --fail -s http://iot-agent:4041/iot/about || exit 1

After docker-compose up I do provision a service and a device like in the tutorial and send the c|1 message to the according topic of the motion sensor (/4jggokgpepnvsb2uv4s40d59ov/motion001/attrs). But the IoT-Agent does not receive anything. I guess the connection to the broker fails. Can anyone please tell me what I am doing wrong here (most likely serveral things)? Do these environmentals even work with the iot-agent-ul? I found them in the documentation of the iotagent-json.

Edit: I changed the docker-image to iotagent-json and at least now it connects to the broker.

Bad request when provisioning actuator

I am following the tutorial as it is without any change.

When provisioning an actuator :

curl -iX POST \
  'http://localhost:4041/iot/devices' \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: openiot' \
  -H 'fiware-servicepath: /' \
  -d '{
  "devices": [
    {
      "device_id": "bell001",
      "entity_name": "urn:ngsi-ld:Bell:001",
      "entity_type": "Bell",
      "protocol": "PDI-IoTA-UltraLight",
      "transport": "MQTT",
      "commands": [
        { "name": "ring", "type": "command" }
       ],
       "static_attributes": [
         {"name":"refStore", "type": "Relationship","value": "urn:ngsi-ld:Store:001"}
      ]
    }
  ]
}
'

I get this error message:

{
    "message": "Request error connecting to the Context Broker: {\"code\":\"400\",\"reasonPhrase\":\"Bad Request\",\"details\":\"JSON Parse Error: unknown field: /contextRegistrations/contextRegistration/attributes/attribute/isDomain\"}",
    "name": "BAD_REQUEST"
}

Here is the iot-agent about json response :

docker run --network fiware_default --rm appropriate/curl -s \
 -X GET 'http://iot-agent:4041/iot/about'
{"libVersion":"2.6.0","port":"4041","baseRoot":"/","version":"1.6.0"}

Error Mosquitto Docker

Hi,

When running the ./services start command I get the following error on the Mosquitto Container. Is able to start the rest of the containers except the mosquitto one. No errors on services create.

$ ./services start
Force removal of mqtt-subscriber
mqtt-subscriber not running
Stopping containers
Stopping fiware-orion ... done
Stopping db-mongo ... done
Removing fiware-orion ... done
Removing db-mongo ... done
Removing mosquitto ... done
Starting five containers Orion, IoT-Agent, Tutorial, Mosquitto MQTT broker and a MongoDB database.

  • Orion is the context broker
  • IoT-Agent is configured for the UltraLight Protocol
  • Tutorial acts as a series of dummy IoT Sensors over MQTT
  • Mosquitto acts as an MQTT Message BrokerCreating mosquitto ... error
    Creating db-mongo ...ERROR: for mosquitto Cannot start service mosquitto: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused "rootfs_linux.go:58: mounting \"/c/FIWARE/tutorial_mqtt/tutorials.IoT-over-MQTT/mosquitto/mosquitto.conf\" to rootfs \"/mnt/sda1/var/lib/docker/overlay2/20c863e6a6b2804927e8aa036e2be468e8b983227684bfad09e2dc9ab889f25f/merged\" at \"/mnt/sda1/var/lib/docker/overlay2/20c863e6a6b2804927e8aa036e2be468e8b983227684bfad09e2dc9ab889f25f/merged/mosquitto/config/mosquitto.conf\" caused \"not a directory\""": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the spCreating db-mongo ... done
    Creating fiware-orion ... doneERROR: for mosquitto Cannot start service mosquitto: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused "rootfs_linux.go:58: mounting \"/c/FIWARE/tutorial_mqtt/tutorials.IoT-over-MQTT/mosquitto/mosquitto.conf\" to rootfs \"/mnt/sda1/var/lib/docker/overlay2/20c863e6a6b2804927e8aa036e2be468e8b983227684bfad09e2dc9ab889f25f/merged\" at \"/mnt/sda1/var/lib/docker/overlay2/20c863e6a6b2804927e8aa036e2be468e8b983227684bfad09e2dc9ab889f25f/merged/mosquitto/config/mosquitto.conf\" caused \"not a directory\""": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
    Encountered errors while bringing up the project.

Error on docker-compose.yml

Executing ./service create , an error is showed

"Pulling tutorial ... error"

" image: fiware/tutorials.context-provider" was commented on docker-compose.yml

and added

image: tutorial

This change is incorrect

Issue when provisioning an actuator

I am using the following python code to create a service group

import json
import requests

url = 'http://localhost:4041/iot/services'
headers = {'Content-Type': "application/json", 'fiware-service': "openiot", 'fiware-servicepath': "/mtp"}

data = {
 "services": [
   {
     "apikey":      "456dgffdg56465dfg",
     "cbroker":     "http://orion:1026",
     "entity_type": "Door",
     #resource attribute is left blank since HTTP communication is not being used
     "resource":    ""
   }
 ]
}
res = requests.post(url, json=data, headers=headers)
#print(res.status_code)

if res.status_code == 201:
    print("Created")

elif res.status_code == 409:
    print("A resource cannot be created because it already exists")

else:
    print (res.raise_for_status())

But when trying to provision an actuator I get a bad request 400 error with the code below:

import json
import requests

url = 'http://localhost:4041/iot/devices'
headers = {'Content-Type': "application/json", 'fiware-service': "openiot", 'fiware-servicepath': "/mtp"}

data = {
 "devices": [
    {
      "device_id": "door003",
      "entity_name": "urn:ngsi-ld:Door:door003",
      "entity_type": "Door",
      "protocol": "PDI-IoTA-UltraLight",
      "transport": "MQTT",
      "commands": [
        {"name": "unlock","type": "command"},
        {"name": "open","type": "command"},
        {"name": "close","type": "command"},
        {"name": "lock","type": "command"}
       ],
       "attributes": [
        {"object_id": "s", "name": "state", "type":"Text"}
       ]
    }
  ]
}

res = requests.post(url, json=data, headers=headers)
#print(res.status_code)

if res.status_code == 201:
    print("Created")

elif res.status_code == 409:
    print("Entity cannot be created because it already exists")

else:
    print (res.raise_for_status())

Here is the error message I get in console.

iot-agent            | time=2021-02-17T11:39:44.132Z | lvl=DEBUG | corr=16f27639-49c2-4419-a926-2433805dbdb3 | trans=16f27639-49c2-4419-a926-2433805dbdb3 | op=IoTAgentNGSI.GenericMiddlewares | from=n/a | srv=smartdoor | subsrv=/mtp | msg=Error [BAD_REQUEST] handling request: Request error connecting to the Context Broker: 501 | comp=IoTAgent
iot-agent            | time=2021-02-17T11:39:44.133Z | lvl=DEBUG | corr=390f5530-f537-4efa-980a-890a44153811 | trans=390f5530-f537-4efa-980a-890a44153811 | op=IoTAgentNGSI.DomainControl | from=n/a | srv=smartdoor | subsrv=/mtp | msg=response-time: 29 | comp=IoTAgent

What is strange is that if a remove the commands from the payload the device provisioning works fine. Is there something am I doing wrong while trying to provision an actuator (not a sensor)?

IoT Agent version:
{"libVersion":"2.14.0-next","port":"4041","baseRoot":"/","version":"1.15.0-next"}

Orion version:

{
"orion" : {
  "version" : "2.2.0",
  "uptime" : "0 d, 0 h, 59 m, 18 s",
  "git_hash" : "5a46a70de9e0b809cce1a1b7295027eea0aa757f",
  "compile_time" : "Thu Feb 21 10:28:42 UTC 2019",
  "compiled_by" : "root",
  "compiled_in" : "442fc4d225cf",
  "release_date" : "Thu Feb 21 10:28:42 UTC 2019",
  "doc" : "https://fiware-orion.rtfd.io/en/2.2.0/"
}
}

My docker-compose file looks as follows:

iot-agent:
    image: fiware/iotagent-ul:latest
    hostname: iot-agent
    container_name: iot-agent
    restart: unless-stopped
    depends_on:
        - mongo-db
    networks:
        - default
    expose:
        - "4041"
    ports:
        - "4041:4041"
    environment:
        - IOTA_CB_HOST=orion
        - IOTA_CB_PORT=1026
        - IOTA_NORTH_PORT=4041
        - IOTA_REGISTRY_TYPE=mongodb
        - IOTA_LOG_LEVEL=DEBUG
        - IOTA_TIMESTAMP=true
        - IOTA_CB_NGSI_VERSION=v2
        - IOTA_AUTOCAST=true
        - IOTA_MONGO_HOST=mongo-db
        - IOTA_MONGO_PORT=27017
        - IOTA_MONGO_DB=iotagentul
        - IOTA_PROVIDER_URL=http://iot-agent:4041
        - IOTA_MQTT_HOST=mosquitto
        - IOTA_MQTT_PORT=1883

Thanks in advance.

Regards,

DEVICE_GROUP_NOT_FOUND with MQTT measure

Related: telefonicaid/iotagent-ul#320

For the Ultralight IoT agent, in the previous release 1.7 if an MQTT measure arrived , when the flow of the code looked for a service group resource was ignored. Therefore the tutorial (setting the resource to blank) was fine when run against 1.7. The behaviour of the iot agent has changed for current release 1.8 and I can't see where the change has been documented, so maybe this is unexpected behaviour.

Either way it is fair to say that the current tutorial doesn't work with the current IoT Agent and one of them (or both) needs to be fixed.

Error: Connection refused

I am getting this error "Error: Connection refused" while running below command

docker run -it --rm --name mqtt-subscriber --network fiware_default efrecon/mqtt-client sub -h mosquitto -t "/#"
Error: Connection refused

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.