Skip to content
Frontend of ThingJS.io platform
HTML Vue JavaScript Other
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
build
config
doc/sсheme
release
src
static
test/unit
.babelrc
.editorconfig
.eslintignore
.eslintrc.js
.gitignore
.postcssrc.js
CMakeLists.txt
README.md
fake.c
github
github.pub
package-lock.json
package.json
platform.html

README.md

ThingJS

ThingJS is open source IoT platform. The project is development template of ThingJS platform. Based on vuejs-templates

Main profits

  • Open source
  • Light cross-platform applications
  • Single syntax for any layers (JavaScript)
  • Relevant developing stack (webpack, npm and etc)
  • Runtime and dev dependencies (by npm)
  • Cross-platform, hardware independent data bus (UBUS)
  • Cross-platform, hardware independent resource interfaces
  • Friendly development mode (hot reload, debugger, storage editor and etc)
  • Famous frameworks on board (VueJS, Vuetify)
  • Simple integration with cloud services

Build Setup

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production with minification
npm run build

# build for production and view the bundle analyzer report
npm run build --report

UBUS messages

UBUS is universal bus for communicate between different nodes. Any device can provide the role. Include WEB browser. When you send message to the bus, all nodes receive it. Important - message will be delivered when node is subscriber for this message.

Max length packed in UBUS is 127 bytes

WEB browser side

 //Send message to UBUS with type "hello" and message "cargo"
 window.$bus.$emit(window.$consts.EVENTS.UBUS_MESSAGE, "hello", "payload");
 ...
 //Receiving and showing message from UBUS
 window.$bus.$on(window.$consts.EVENTS.UBUS_MESSAGE, function(type, messages) {
    console.log(`${type}:${messages}`);
 });
 ...
 //Result in console
 hello:payload

Controller side

application manifest

  ...    
  "scripts" : {
    "subscriptions" : ["hello"],
    "entry" : "main",
    "modules" : {
      "main": {
        "source": "scripts/main.js",
        "optimize": false,
        "hot_reload" : true
      }
    }
  }
  ...    

application mjs script scripts/main.js

 //Importing UBUS listener function  
 let listener = ffi('void listener(void (*)(char*, char*, userdata), userdata)');
 
 //When message will received, function will call callback function  
 listener(function(event, content, data) {
    if(event === "hello"){
        print(event, ":", data);
    }
 }, null); 

 //Importing UBUS send function
 let emit = ffi('void emit(char*, char*)');    
 //Sending message to UBUS
 emit('my-script-ready', null);

Predefined system messages

All broadcast system messages is defined in window.$const.UBUS You can send the messages from outside to controller only in develop mode.

Broadcast

  • $-current-time - (CURRENT_TIME) Contains epoch time (ms). Happens when the time is synchronized.
  • $-online - (IS_ONLINE) No content. Happens when the controller connected to Internet.
  • $-offline - (IS_OFFLINE) No content. Happens when the controller disconnected.
  • $-script-error - (SCRIPT_ERROR) Contains error text. Happens when the script generates an error.
  • $-storage-changed - (STORAGE_CHANGED) Contains uri of storage object. Happens when object of storage was changed.
  • $-debugger-request - (DEBUGGER_REQUEST) No content. Happens when mJS meet "debugger" command in script. (dev mode only)

JavaScript

 window.$bus.$on(window.$consts.EVENTS.UBUS_MESSAGE, function(type, messages) {
    switch(type){
        case window.$consts.UBUS.CURRENT_TIME:
            console.log('Now is ', new Date(1 * messages));
            break;
        case window.$consts.UBUS.SCRIPT_ERROR:
            console.error('Script error: ', messages);
            break;
    }
 });

Specific massages for controller side script

  • $-started - No content. Happens when the controller starts or script installed.

Specific massages for core controller

  • $-script-restart - Contains application name. Do start/restart script process.
  • $-script-stop - Contains application name. Do terminate script process.

mjs script

 let listener = ffi('void listener(void (*)(char*, char*, userdata), userdata)');
 listener(function(event, content, data) {
    if(event === "$-started"){
        print("Controller is ready!");       
    }
 }, null);

Resource interfaces

You can’t perform that action at this time.