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 json

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, loop, pan):
        self.pan = pan
        loop.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 await self.pan.updateDisplay(target, layout)

This “hello-world” App sends a text 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). The ‘loop’ is the asyncio loop object, which is used to create any async tasks later.

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

Please learn the asyncio here: https://github.com/peterhinch/micropython-async/blob/master/TUTORIAL.md