Closed SrdjanZec closed 2 years ago
Hi all, I am able to connect to the agent, but it gives me a Parse error parsing incoming message[%] forcing to hex string, what does it mean? Also lvl=FATAL Ignoring:Type Error parsedMessage.reduce is not a function. What does it mean?
Solved! I was using the wrong IOT Agent.
Hi GitHub Community, I am trying to connect raspberry pi with FIWARE Orion context broker system using MQTT protocol. I am using python3 mqtt_publisher.py codein order to publish the mqtt JSON data, I am connecting to the mosquitto docker container. The server (my laptop) has 4 docker containers so far, Mosquitto (in this case is used as MQTT broker), IOT-JSON-Agent (gets data from MQTT broker and pass it to Orion Context Broker), Orion Context Broker (uses that data and stores it in MongoDB). I have some issues, so i will try to present them here if someone can help me. `#MQTT PUBLISHER import json import random import time import paho.mqtt.client as mqtt
THE_BROKER = " " # my laptops ip address THE_TOPIC = "/12345/SensTemp/attrs" #MQTT topic, important CLIENT_ID =""
The callback for when the client receives a CONNACK response from the server
def on_connect(client, userdata, flags, rc): print("Connected to ", client._host, "port: ",client._port) print("Flags: ", flags, "returned code: ", rc)
The callback for when a message is published
def on_publish(client, userdata, mid): print("Yespub: msg published (mid={})".format(mid))
client = mqtt.Client(client_id=CLIENT_ID, clean_session=True, userdata=None, protocol=mqtt.MQTTv311, transport= "tcp")
client.on_connect = on_connect client.on_publish = on_publish client.connect(THE_BROKER, port=1883, keepalive=60) #The port of the mosquitto docker container
client.loop_start()
while True: s = {} s['the_temperature'] = random.randint(0,100) j = json.dumps(s)
msg_to_be_sent = j print(j) client.publish(THE_TOPIC, payload=msg_to_be_sent, qos = 1, retain = False) time.sleep(15)
client.loop_stop()
And here is the docker-compose.yml file:
version: "3.3" services:After some REST commands, in this case so far i have created of a service Group with these commands: `curl -iX POST \
'http://localhost:4041/iot/services' \
-H 'content-type: application/json' \
-H 'fiware-service: myClassRoom' \
-H 'fiware-servicepath: /' \
-d'{
}'
Also I have created a Device in the IOT-Agent like this:
curl -iX POST \'http://localhost:4041/iot/devices' \ -H 'content-type: application/json' \ -H 'fiware-service: myClassRoom' \ -H 'fiware-servicepath: /' \ -d '{ "devices": [ { "device_id": "SensTemp", "entity_name": "urn:ngsi-ld:temperature-sensor:001", "entity_type": "Device", "protocol": "PDI-IoTA-UltraLight", "transport": "MQTT", "timezone": "Europe/Madrid", "attributes": [ { "object_id": "temperature", "name": "temperature", "type": "Integer" } ] } ] }'
` The server responded with HTTP 201 Response, but i think the agent is not processing data the right way, can someone give me a pointer on how can i register the device in context broker? Maybe i need to do that as well?