Fork me on GitHub

Video tutorials

Listing, reading, saving, deleting files

mos ls             # List files
mos get FILENAME   # Print contents of FILENAME
mos put FILENAME   # Copy FILENAME to the device
mos rm FILENAME    # Delete FILENAME

Using built-in web server

mos get index.html > a  # Fetch index.html
vim a                   # Edit local file
mos put a index.html    # Upload back to index.html

Getting and setting device configuration

mos config-get
mos config-set debug.level=3
mos config-set mqtt.server=a.b.c:12345

Programming in JavaScript - adding an RPC service

mos call Control '{"state": 0}'
mos call GetNetworkStatus
curl -d '{"state": 1}' ws://IP/rpc/Control
mos --port ws://IP/rpc call Control '{"state": 0}'
mos --port mqtt://MQTT_SERVER:PORT/DEVICE_ID call Control '{"state": 0}'

Programming in C/C++ - adding an RPC service

mos init --arch esp8266   # Initialise empty project
mos build                 # Build firmware
mos flash                 # Flash firmware
mos call Control '{"state": 0}'  # See prev. tutorial

Built-in RPC services

mos call RPC.List
mos call RPC.Describe '{"name": "GPIO.Write"}'
mos call GPIO.Write '{"pin": 16, "value": 0}'

Over-the-Air update (OTA)

mos --port ws://DEVICE_IP/rpc call OTA.Update '{"url": "http://MYSITE/", "commit_timeout": 100}'
mos --port ws://DEVICE_IP/rpc call OTA.Commit

MQTT publish and subscribe

let pin = 0, topic = 'my/topic';
GPIO.set_button_handler(pin, GPIO.PULL_UP, GPIO.INT_EDGE_NEG, 200, function() {'my/topic', JSON.stringify({ a: 1, b: 2 }));
}, null);
MQTT.sub('my/topic/#', function(conn, topic, msg) {
  print('Topic:', topic, 'message:', msg);
}, null);

AWS device shadows

let state = { on: false, counter: 0 };  // device state: shadow metadata
let buttonPin = 0;
GPIO.set_button_handler(buttonPin, GPIO.PULL_UP, GPIO.INT_EDGE_NEG, 200, function() {
  AWS.Shadow.update(0, {desired: {on: state.on, counter: state.counter + 1}});
}, null);

ESP32 flash encryption

mos flash esp32
mos flash-read --arch esp32 0x190000 2000 -
mos -X esp32-gen-key flash_encryption_key fe.key \
  --esp32-enable-flash-encryption --dry-run=false
mos flash esp32 --esp32-encryption-key-file fe.key