import mojoscale_messaging
The mojoscale_messaging module exposes device-scoped realtime channels. MQTT topics, broker credentials, and internal Studio update topics remain managed by MojoScale.
Quick example
import mojoscale_messaging
temperature = mojoscale_messaging.channel("temperature")
def on_ready():
temperature.send({"temp": 23.4, "unit": "C"})
def on_message(message):
print(message)
mojoscale_messaging.on_connect(on_ready)
mojoscale_messaging.connect()
temperature.subscribe(on_message)
# Equivalent lower-level form if you prefer module functions:
mojoscale_messaging.send(temperature, {"temp": 23.4})
importmojoscale_messaging
MojoScale device channel messaging.
The mojoscale_messaging module exposes device-scoped realtime channels. MQTT topics, broker credentials, and internal Studio update topics remain managed by MojoScale.
mojoscale_messaging.channel(name: str) -> channel
mojoscale_messaging.channel(name: str) -> channelCreate a device-scoped messaging channel handle.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
name |
str |
positional or keyword | Yes | Channel name. Use letters, numbers, underscores, hyphens, or dots. Names starting with "__studio__" are reserved for Studio libraries. |
channel Messaging channel handle. Use handle.send(message_payload) and handle.subscribe(callback) in Studio code.
mojoscale_messaging.connect() -> bool
mojoscale_messaging.connect() -> boolConnect to Studio-managed MojoScale Messaging.
The device uses the managed credentials flashed by Studio. Register on_connect(callback) before connect() when you want to publish only after the broker connection is ready.
bool True if the managed MQTT connection was started or already active.
mojoscale_messaging.connected() -> bool
mojoscale_messaging.connected() -> boolCheck whether Studio-managed MojoScale Messaging is connected.
bool True when the managed messaging connection is active.
mojoscale_messaging.on_connect(callback: callback) -> bool
mojoscale_messaging.on_connect(callback: callback) -> boolRegister a callback for MojoScale Messaging connection.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
callback |
callback |
positional or keyword | Yes | Named global function to run when Studio-managed messaging connects. Pass the function without quotes; Studio sends its name string to firmware. |
bool True if the callback was registered.
mojoscale_messaging.on_disconnect(callback: callback) -> bool
mojoscale_messaging.on_disconnect(callback: callback) -> boolRegister a callback for MojoScale Messaging disconnection.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
callback |
callback |
positional or keyword | Yes | Named global function to run when Studio-managed messaging disconnects. Pass the function without quotes; Studio sends its name string to firmware. |
bool True if the callback was registered.
mojoscale_messaging.send(channel: channel, message_payload: list) -> bool
mojoscale_messaging.send(channel: channel, message_payload: list) -> boolSend a realtime message on a channel.
Users normally call this as handle.send(message_payload). Studio rewrites that friendly channel-handle form to the native firmware call. The module-level form is also valid as mojoscale_messaging.send(handle, message_payload).
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
channel |
channel |
positional or keyword | Yes | Messaging channel handle returned by mojoscale_messaging.channel(name). |
message_payload |
list |
positional or keyword | Yes | Message to send. Strings, numbers, booleans, lists, and dicts are accepted. Literal dict/list payloads are serialized to JSON by Studio. |
bool True if the message was accepted for publish.
mojoscale_messaging.subscribe(channel: channel, callback: callback) -> bool
mojoscale_messaging.subscribe(channel: channel, callback: callback) -> boolReceive realtime messages from a channel.
Users normally call this as handle.subscribe(callback). Studio rewrites that friendly channel-handle form to the native firmware call. The module-level form is also valid as mojoscale_messaging.subscribe(handle, callback). The callback receives one message argument.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
channel |
channel |
positional or keyword | Yes | Messaging channel handle returned by mojoscale_messaging.channel(name). |
callback |
callback |
positional or keyword | Yes | Named global function to run for each inbound message. Pass the function without quotes; Studio sends its name string to firmware. |
bool True if the subscription was registered.
mojoscale_messaging.turn_off_wireless_update() -> bool
mojoscale_messaging.turn_off_wireless_update() -> boolDisable Studio wireless update commands for this script.
Importing mojoscale_messaging automatically enables Studio-managed messaging and wireless script update support. Call this if the script only needs user channels and should not listen for Studio update commands.
bool True when the internal update listener was disabled.