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()
Metadata
Release files for nodewire 2.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| nodewire-2.0.2.tar.gz | 11.0 kB | Details |
Release files / nodewire-2.0.2.tar.gz
| Download URL | nodewire-2.0.2.tar.gz |
|---|---|
| Size | 11.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
46078eee6ef3dde82d26bafeef191f97b00dd5480ecb585cacd824e9b584e5a8
|
|
BLAKE2b-256 checksum How to use checksums |
aeb95674358a6bd0cd00ef95504387419cf90b76e9dc6537e055953cc130cc56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|