Hello World

Introduction

“Hello World” Plug-in Explain

You can download the tutorial’s final sample project from this Github Page: https://github.com/myvobot/examples/tree/master/hello_world

Introduction

The Hub Plug-in awaits any node appears online, then use the “Layout Template” to render the content of the screen.

Here is an example of a Hub Plug-in:

import uasyncio as asyncio
import ujson as json
from core.pan_parameters import QOS1

TEMPLATE = '''
{
    "items": [
        { "type": "TEXT",
        "data": {
            "text": "HELLO WORLD",
            "block": { "x": 120, "y": 110, "w": 200, "h": 56 }
        }
        }
    ]
}
'''

class App:
    # User Plug-in of Hub SDK, send a 'Hello world' to the wireless display

    def __init__(self, mgr):
        self.pan = mgr.pan
        asyncio.create_task(self.printHello()) # run a asyncio coro task

    async def printHello(self):
        # Wait for at least one display node becomes online
        while 0 == len(self.pan.onlineNodes()):
            await asyncio.sleep(1)
        # Create layout render template and send to display
        layout = json.loads(TEMPLATE)
        # Select the first online node as the target
        target = next(iter(self.pan.onlineNodes()))
        return self.pan.putRefreshQueue(target, layout, qos = QOS1)

This “hello-world” App sends a ‘layout document’ with text block to the first display available.

The Hub’s built-in system will use ‘import app’ to load the module inside /app folder. This example has only one file __init__.py, and then the system will create a App() object; thus, the __init__() is called.

Here, ‘pan’ is the object of the local mesh network (Personal Area Network, PAN).

Then runs the co-routine task, printHello(). It waits for at least one display node becomes online, then send a ‘layout’ json to the node.

Please learn the asyncio here: https://github.com/peterhinch/micropython-async