Compare commits
19 Commits
7ddfb68b02
...
2f8235965e
| Author | SHA1 | Date | |
|---|---|---|---|
| 2f8235965e | |||
| eee4743d4d | |||
| b3162e11bd | |||
| 12f6b9871f | |||
| ceb9037dc4 | |||
| 2935a9349d | |||
| b772848d4c | |||
| 722d45b2a1 | |||
| ad07896ba3 | |||
| 4ff31c0884 | |||
| de8d2516f6 | |||
| c291f150af | |||
| 2cdd8d1bd0 | |||
| 9276239d41 | |||
| a9673c1070 | |||
| 9a4aeec6cb | |||
| d1be717490 | |||
| b330180909 | |||
|
|
b2c7427af0 |
25
.gitea/workflows/testing.yaml
Normal file
25
.gitea/workflows/testing.yaml
Normal file
@ -0,0 +1,25 @@
|
||||
name: Test Agent
|
||||
on: [push, workflow_dispatch]
|
||||
jobs:
|
||||
test-agent-run:
|
||||
runs-on: arch-x86_64
|
||||
steps:
|
||||
- name: Fetch the repository
|
||||
run: git clone --branch ${{ gitea.ref_name }} --depth 1 ${{ gitea.server_url }}/${{ gitea.repository }}
|
||||
|
||||
- name: Build containers
|
||||
run: docker-compose -f docker-compose-test.yaml build
|
||||
working-directory: sem8-iot-test/agent/docker
|
||||
|
||||
- name: Start MQTT broker
|
||||
run: docker-compose -f docker-compose-test.yaml up -d mqtt
|
||||
working-directory: sem8-iot-test/agent/docker
|
||||
|
||||
- name: Start agent
|
||||
run: docker-compose -f docker-compose-test.yaml run fake_agent
|
||||
working-directory: sem8-iot-test/agent/docker
|
||||
|
||||
- name: Clean up
|
||||
if: always()
|
||||
run: docker-compose -f docker-compose-test.yaml down
|
||||
working-directory: sem8-iot-test/agent/docker
|
||||
34
agent/docker/docker-compose-test.yaml
Normal file
34
agent/docker/docker-compose-test.yaml
Normal file
@ -0,0 +1,34 @@
|
||||
version: "3.3"
|
||||
#name: "road_vision"
|
||||
services:
|
||||
mqtt:
|
||||
image: eclipse-mosquitto
|
||||
container_name: mqtt
|
||||
volumes:
|
||||
- ./mosquitto:/mosquitto
|
||||
- ./mosquitto/data:/mosquitto/data
|
||||
- ./mosquitto/log:/mosquitto/log
|
||||
ports:
|
||||
- 1883:1883
|
||||
- 9001:9001
|
||||
networks:
|
||||
mqtt_network:
|
||||
|
||||
|
||||
fake_agent:
|
||||
container_name: agent
|
||||
build: ../
|
||||
depends_on:
|
||||
- mqtt
|
||||
environment:
|
||||
MQTT_BROKER_HOST: "mqtt"
|
||||
MQTT_BROKER_PORT: 1883
|
||||
MQTT_TOPIC: "agent_data_topic"
|
||||
DELAY: 0.1
|
||||
MAX_SENDS: 30
|
||||
networks:
|
||||
mqtt_network:
|
||||
|
||||
|
||||
networks:
|
||||
mqtt_network:
|
||||
@ -1,4 +1,5 @@
|
||||
name: "road_vision"
|
||||
version: "3.3"
|
||||
#name: "road_vision"
|
||||
services:
|
||||
mqtt:
|
||||
image: eclipse-mosquitto
|
||||
|
||||
@ -16,3 +16,6 @@ MQTT_TOPIC = os.environ.get("MQTT_TOPIC") or "agent"
|
||||
|
||||
# Delay for sending data to mqtt in seconds
|
||||
DELAY = try_parse(float, os.environ.get("DELAY")) or 1
|
||||
|
||||
# Testing switches for CI/CD
|
||||
MAX_SENDS = try_parse(int, os.environ.get("MAX_SENDS"))
|
||||
|
||||
@ -22,9 +22,13 @@ def connect_mqtt(broker, port):
|
||||
return client
|
||||
|
||||
|
||||
def publish(client, topic, datasource):
|
||||
def publish(client, topic, datasource, max_sends = None):
|
||||
datasource.startReading()
|
||||
|
||||
i = 0
|
||||
while True:
|
||||
i += 1
|
||||
|
||||
data = datasource.read()
|
||||
msg = AggregatedDataSchema().dumps(data)
|
||||
result = client.publish(topic, msg)
|
||||
@ -32,6 +36,10 @@ def publish(client, topic, datasource):
|
||||
if status != 0:
|
||||
print(f"Failed to send message to topic {topic}")
|
||||
|
||||
if max_sends and i >= max_sends:
|
||||
# display test success
|
||||
exit(0)
|
||||
|
||||
|
||||
def run():
|
||||
# Prepare mqtt client
|
||||
@ -39,8 +47,8 @@ def run():
|
||||
# Prepare datasource
|
||||
datasource = FileDatasource("data/accelerometer.csv", "data/gps.csv")
|
||||
# Infinity publish data
|
||||
publish(client, config.MQTT_TOPIC, datasource)
|
||||
publish(client, config.MQTT_TOPIC, datasource, getattr(config, "MAX_SENDS", None))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
run()
|
||||
|
||||
@ -13,6 +13,7 @@ services:
|
||||
- 19001:9001
|
||||
networks:
|
||||
mqtt_network:
|
||||
user: 1000:1000
|
||||
|
||||
|
||||
edge:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user