Ruuvi Sensor Integration Example
This integration demonstrates how to connect DeltaV agents with a local agent communicating with a Ruuvi sensor on a Raspberry Pi 4.
Prerequisites
Ensure the following prerequisites are met, as detailed here: ruuvitag-sensor GitHub repository.
Raspberry Pi 4 Setup
Install the latest released version of the ruuvitag-sensor:
python -m pip install ruuvitag-sensor
Agentverse implementation
Create an Agent on Agentverse.ai with the following code:
from ai_engine import UAgentResponse, UAgentResponseType from model import DeltaVRequest LOCAL_AGENT_ADDRESS = "agent1qg6szxmy86t6jjv4xl55esnzdezcfns02kw52lsdwsf6287z9k83srvjx70" proto = Protocol(name="Sauna DeltaV", version="0.1") @proto.on_message(model=DeltaVRequest, replies={UAgentResponse}) async def handle_delta_request_message(ctx: Context, sender: str, msg: DeltaVRequest): ctx.logger.info(f"Received message from DeltaV: {sender}, session: {ctx.session}") ctx.storage.set("consumer_address", sender) await ctx.send(LOCAL_AGENT_ADDRESS, msg) ctx.logger.info("Sending to local from DeltaV") @agent.on_message(model=UAgentResponse) async def handle_message(ctx: Context, sender: str, msg: UAgentResponse): ctx.logger.info("Received message from local agent") consumer_address = ctx.storage.get("consumer_address") await ctx.send(consumer_address, msg) agent.include(proto, publish_manifest=True)
and model.py:
class DeltaVRequest(Model): text: str
Create a service on Agentverse.ai for our agent and link it to its method.
Raspberry Pi 4 local agent implementation
Create a local agent on Raspberry Pi 4
You can find the agent code in the agent.py file. The idea is that it will listen to a sensor with a MAC address from the macs array. Set your sensor's MAC address (you can find it using the Ruuvi Station app for iPhone here and for Android here).
Create a mailbox on Agentverse.ai with the address of the local agent. You're all set.
Run the local agent and the agent on Agentverse.ai and try asking DeltaV for the temperature in your sauna. You will receive the result directly from the sensor with all data from sensor.
Note: The agent has been tested and works on Raspberry Pi 4, making it convenient and essentially capable of connecting with any sensors in general.