Nodewire
Project description
Introduction
This package enables you to:
Create software that connects to IoT devices for monitoring and control
Create microservices
NodeWire uses a dataflow programming model. Nodes have input and output ports through which it receives and sends messages. A NodeWire program can connect to other nodes to monitor and send messagesto it.
Hello NodeWire
import asyncio from nodewire import Node class MyNode(Node): def on_reset(self, value, sender): self.count = value def get_status(self, sender): return { 'counting': self.start==1, 'count': self.count } async def loop(self): print('connected') while True: await asyncio.sleep(1) if self.start==1: self.count = self.count + 1 mynode = MyNode(nodename='hello', inputs='start reset', outputs='count status', server='localhost') mynode.nw.debug = True mynode.nw.run()
First we created our node class. In this class, we defined message handlers that will be called when the system wants to determine the value of our output ports (get_portname) or when it wants to forward a new value to us (on_portname). Note that you can chose to define handlers for some ports (reset and status in this example), or chose not to (start and count). You also have the choice to make thehandler syncronous or asyncronous. If the handler is going to take a long time to run, then it is better to make it asyncronous and use asyncio.sleep every once in a while, so that other tasks will get a chance to run.
The loop function is special. It is called only once, the first time the node establishes a successful connection to the server. It must be an async function. This function is meant to serve as the mainloop of your nodewire application but you can also terminate it without any effect on the overal running of the run. The loop function is optional
Control and Monitor
from nodewire import Node class MyNode(Node): def got_count(self, nodename): print(counter.count) if counter.count == 10: counter.reset = 0 async def loop(self): global counter print('connected') counter = await self.get_node('hello') counter.start = 1 counter.on_count = self.got_count mynode = MyNode(nodename='control', server='localhost') mynode.nw.run()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file nodewire-2.0.2.tar.gz
.
File metadata
- Download URL: nodewire-2.0.2.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46078eee6ef3dde82d26bafeef191f97b00dd5480ecb585cacd824e9b584e5a8 |
|
MD5 | 0ed3c6e9b189bceb6c2ecb8b779a4148 |
|
BLAKE2b-256 | aeb95674358a6bd0cd00ef95504387419cf90b76e9dc6537e055953cc130cc56 |