Skip to content

chore: adapt changes to iota according to new version#485

Open
sbanoeon wants to merge 19 commits intomasterfrom
333-iot-agent-drops-routes-iotservices
Open

chore: adapt changes to iota according to new version#485
sbanoeon wants to merge 19 commits intomasterfrom
333-iot-agent-drops-routes-iotservices

Conversation

@sbanoeon
Copy link
Copy Markdown
Contributor

@sbanoeon sbanoeon commented Feb 25, 2026

Closes #333

@sbanoeon sbanoeon requested a review from djs0109 February 25, 2026 07:59
@sbanoeon sbanoeon linked an issue Feb 25, 2026 that may be closed by this pull request
print("Wrong port error message:", str(cm.exception))
self.assertIsInstance(cm.exception.__cause__, requests.RequestException)

@pytest.mark.skip(reason="Not ready yet")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djs0109 These are the tests which are still failing.

entity.delete_attributes(["test3"])
self.assertEqual(entity.get_attribute_names(), set())

@pytest.mark.skip(reason="Not ready yet")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djs0109 These are the tests which are still failing.


self.client.delete_entity(entity_id="string_test", entity_type="test_type1")

@pytest.mark.skip(reason="Not ready yet")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djs0109 These are the tests which are still failing.

@djs0109 djs0109 mentioned this pull request Mar 16, 2026
@djs0109
Copy link
Copy Markdown
Collaborator

djs0109 commented Mar 17, 2026

Regarding commands I found the latest documentation

@djs0109
Copy link
Copy Markdown
Collaborator

djs0109 commented Apr 1, 2026

Here is a script to test the mqtt command of iotagent

import requests
import time
import paho.mqtt.client as mqtt
import paho.mqtt.publish as publish
from paho.mqtt.enums import CallbackAPIVersion

# ==========================================
# CONFIGURATION & SETUP
# ==========================================
HOST = "..." # TODO
IOTA_URL = f"http://{HOST}:4041"
ORION_URL = f"http://{HOST}:1026"
MQTT_PORT = 1883
API_KEY = "testapikey"

# Initialize a session to avoid repeating headers
session = requests.Session()
session.headers.update({
    'fiware-service': 'filip_jdu',
    'fiware-servicepath': '/'
})

def print_response(step_name, response):
    """Helper function to print responses clearly."""
    print(f"\n--- {step_name} ---")
    print(f"Status Code: {response.status_code}")
    print(response.text)

def on_connect(client, userdata, flags, rc):
    print(f"\n[MQTT] Connected to broker with result code {rc}")
    # Subscribe to all topics using the wildcard '#'
    client.subscribe("#")

def on_message(client, userdata, msg):
    print(f"\n[MQTT MESSAGE RECEIVED] Topic: {msg.topic} | Payload: {msg.payload.decode()}")

# Setup the MQTT client and start the listening loop in the background
mqtt_client = mqtt.Client(callback_api_version=CallbackAPIVersion.VERSION1)
mqtt_client.on_connect = on_connect
mqtt_client.on_message = on_message
mqtt_client.connect(HOST, MQTT_PORT, 60)
mqtt_client.loop_start()

# Give the MQTT client a brief moment to connect before firing API requests
time.sleep(1)

# ==========================================
# API EXECUTION FLOW
# ==========================================

# 1. Get IoT Agent Version
res = session.get(f"{IOTA_URL}/version")
print_response("IoT Agent Version", res)

# 2. Create Group
group_payload = {
    "groups": [
        {
            "resource": "/iot/json",
            "apikey": API_KEY,
            "entity_type": "Actuator",
            "transport": "MQTT"
        }
    ]
}
res = session.post(f"{IOTA_URL}/iot/groups", json=group_payload)
print_response("Create Group", res)

# 3. Get Groups
res = session.get(f"{IOTA_URL}/iot/groups")
print_response("Get Groups", res)

# 4. Create Sensor Device
sensor_payload = {
    "devices": [
        {
            "device_id": "sensor:001",
            "entity_name": "sensor:001",
            "entity_type": "sensor",
            "apikey": API_KEY,
            "attributes": [{"name": "temperature", "type": "Number"}],
            "ngsiVersion": "v2"
        }
    ]
}
res = session.post(f"{IOTA_URL}/iot/devices", json=sensor_payload)
print_response("Create Sensor Device", res)

# 5. Send MQTT msg to simulate sensor reading
print("\n--- Sending MQTT Sensor Reading ---")
sensor_topic = f"/json/{API_KEY}/sensor:001/attrs"
sensor_msg = '{"temperature": 20}'
publish.single(sensor_topic, payload=sensor_msg, hostname=HOST, port=MQTT_PORT)
time.sleep(1) # Pause slightly to allow Orion to process the update

# 6. Check Entity (sensor:001)
res = session.get(f"{ORION_URL}/v2/entities/sensor:001")
print_response("Check Sensor Entity in Orion", res)

# 7. Create Actuator Device
actuator_payload = {
    "devices": [
        {
            "device_id": "actuator:004",
            "entity_name": "actuator:004",
            "entity_type": "Actuator",
            "cmdMode": "notification",
            "apikey": API_KEY,
            "commands": [{"name": "on", "type": "command"}],
            "ngsiVersion": "v2"
        }
    ]
}
res = session.post(f"{IOTA_URL}/iot/devices", json=actuator_payload)
print_response("Create Actuator Device", res)

# 8. Check Subscription Created
res = session.get(f"{ORION_URL}/v2/subscriptions/")
print_response("Check Subscriptions", res)

# 9. Update Command (Send command to Actuator)
command_payload = {
    "on": {
        "type": "command",
        "value": 1
    }
}
res = session.patch(f"{ORION_URL}/v2/entities/actuator:004/attrs?type=Actuator", json=command_payload)
print_response("Send Command to Actuator", res)

# Keep script running briefly to ensure the background MQTT listener catches the final command
time.sleep(2)
mqtt_client.loop_stop()

@djs0109
Copy link
Copy Markdown
Collaborator

djs0109 commented Apr 8, 2026

@sbanoeon could you please test the behavior as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IoT-Agent drops routes /iot/services

2 participants