Examples¶
This section contains practical examples for the use of the DaaS-IoT Python wrapper (pydaasiot).
Each example assumes that your environment is already configured as described in the installation guide
(e.g., config.json is available and the library is installed).
1. Simple Sender/Receiver¶
This pair of scripts shows the minimal setup for two Python nodes exchanging a text message over IPv4 on localhost.
-
sender.py
Initializes a node withSID=100, localDIN=102, maps a receiver withDIN=101and sends the message"Hello from sender!"as a DDO. -
receiver.py
Initializes a node withSID=100, localDIN=101, maps the sender withDIN=102and prints the received payload usingpayload_text().
How to run¶
- Start the receiver in the first terminal:
python receiver.py
- Start the sender in a second terminal:
python sender.py
- You should see:
- on the sender side: the push result
- on the receiver side: the payload printed in the console.
2. Generic DaaS Node (interactive CLI)¶
This example implements a generic DaaS-IoT node that can be deployed on a VPS or any host, and exposes a small interactive CLI to send text messages as DDO payloads.
Script: daas_node.py
Main features:
- configurable
SID, localDINand local driver address (ip:port) - optional mappings to remote nodes via
--map REMOTE_DIN REMOTE_ADDR - logs incoming events and, on
ddoReceivedEvent, performspull()and printspayload_text() - runs a background input thread that:
- asks for target DIN
- asks for typeset
- asks for a message
- sends a DDO via
push()
How to run¶
Example:
python daas_node.py --sid 100 --din 101 --addr "0.0.0.0:3001" --config config.json --map 102 "127.0.0.1:3002"
Once started, follow the interactive prompts in the terminal to choose the destination DIN, typeset and message body to send.
3. Basic Hub (DDO Forwarding with Stats)¶
This example implements a basic hub node that receives DDOs from mapped peers, prints their payload, keeps simple per-DIN statistics and forwards the same DDO to all other peers.
Script: daas_hub.py
Typical use case:
- a central hub with its own
SID/DINand address - multiple nodes mapped as peers
- when one node sends a DDO to the hub, the hub forwards it to the others.
How to run¶
Start the hub, for example:
python daas_hub.py --sid 100 --din 200 --addr "0.0.0.0:4000" --config config.json --peer 101 "127.0.0.1:3001" --peer 102 "127.0.0.1:3002"
Then start two or more generic nodes (for example using daas_node.py), mapping back the hub DIN 200.
When a node sends a DDO to the hub, you should see on the hub console:
- the payload (via
payload_text()) - updated statistics per source DIN
- forwarding logs for each peer.