Skip to content

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 with SID=100, local DIN=102, maps a receiver with DIN=101 and sends the message "Hello from sender!" as a DDO.

  • receiver.py
    Initializes a node with SID=100, local DIN=101, maps the sender with DIN=102 and prints the received payload using payload_text().

How to run

  1. Start the receiver in the first terminal:
python receiver.py
  1. Start the sender in a second terminal:
python sender.py
  1. You should see:
  2. on the sender side: the push result
  3. 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, local DIN and local driver address (ip:port)
  • optional mappings to remote nodes via --map REMOTE_DIN REMOTE_ADDR
  • logs incoming events and, on ddoReceivedEvent, performs pull() and prints payload_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/DIN and 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.