Comments (5)
Websocket API commands include: status, register, unregister, update, whoami, devices, subscribe, unsubscribe, authenticate, and message. The websocket API mimics the skynet.js examples. Here are a few examples:
// Sample SkyNet API calls:
socket.emit('status', function(data){
console.log('status received');
console.log(data);
});
// Subscribe and unsubscribe to a device's messages and events
socket.emit('subscribe', {
"uuid": "0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc",
"token": "qirqglm6yb1vpldixflopnux4phtcsor"
}, function (data) {
console.log(data);
});
socket.emit('unsubscribe', {"uuid": "0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc"}, function (data) {
console.log(data);
});
// Send and receive messages
socket.emit('message', {
"devices": "*",
"payload": {
"skynet":"online"
}}, function(data){
console.log(data);
});
socket.on('message', function(message){
console.log('message received', message);
});
// Get the status of the SkyNet network
socket.emit('status', function(data){
console.log('status received');
console.log(data);
});
// Register device
socket.emit('register', {
"type":"drone"
}, function (data) {
console.log(data);
});
// Update device
socket.emit('update', {
"uuid": "0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc",
"token": "qirqglm6yb1vpldixflopnux4phtcsor",
"armed":true
}, function (data) {
console.log(data);
});
// WhoAmI?
socket.emit('whoami', {"uuid":"0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc"}, function (data) {
console.log(data);
});
// Receive last 10 device events
socket.emit('events', {
"uuid": "0d3a53a0-2a0b-11e3-b09c-ff4de847b2cc",
"token": "qirqglm6yb1vpldixflopnux4phtcsor"
}, function (data) {
console.log(data);
});
from meshblu.
None of those examples show what is returned. All it shows is "console.log(data)". What is data? Is it ever used? Does it vary based on what parameters are sent?
Based on these examples a Websocket client can ignore what comes back and never needs to use it.
I look at these examples and they make little sense because they do not demonstrate any real-word use. What's returned by "events"? Why would it be called only to do console.log?
The examples are too sparse and do not make clear what return data are provided. Makes it hard to write client code in Lua, Java, etc. since there are few explicit details documenting behavior.
from meshblu.
The response results for the websocket API should be the same as the REST API. See http://skynet.im/#api
from meshblu.
"The response results for the websocket API should be the same as the REST API."
They are not. That's part of the problem.
For example, there is no REST item called "register" . Instead, there's a POST to /devices. This lack of a direct correspondence between the tow APIs suggest there are gong to be discrepancies. What are they?
The docs fr posting to /devices' there say, "SkyNet returns a UUID device id and security token. "
When called via the Websocket I get back much more:
{"timestamp":1395357227025,
"_id":"532b762ba8b3766426000009",
"token":"1gk7jckoswp6tj4iisoc4vddy22o6r",
"eventCode":400,
"device":"P5",
"uuid":"4a055811-b085-11e3-8217-79d204ef5ee7",
"channel":"main",
"ipAddress":"",
"online":false}
What do these mean? If my code doesn't do what I expect, would these values (or that fact that some are missing) help explain that?
Since these values get returned there's a presumption that they must mean something and have some practical use. But what? Where is that explained?
The docs and examples seem to be written from the POV of someone who wrote the code and already knows how everything is supposed to work and what to look for if something does not.
There needs to be something more robust to fully describe the protocol. I.e. Here are all the possible arguments you can send, and why you might include or omit them. Here are all the possible values you might get back, what each means and what they could, should, or must be used for.
from meshblu.
I added a new example section to the site with REST, NodeJS, and Skynet.JS examples - http://skynet.im/#examples
I also added responses to the websocket api docs - http://skynet.im/#websockets
from meshblu.
Related Issues (20)
- Help!!! Can not get message when i run meshblu on ubuntu14.04 x64 HOT 2
- Send/Receive messages HOT 5
- Cross-protocol send/Receive messages
- About unifying APIs for all protocols HOT 2
- Retaining messages HOT 1
- TypeError: callback is not a function HOT 2
- config.token or environment variable TOKEN is required. Exiting. HOT 1
- Forwarder of webhook
- Provide a way to run core-dispatcher & protocol adapters
- DispatcherWorker constructor is missing "@pepper on Ubuntu
- DispatcherWorker constructor is missing "@pepper
- meshblu.createConnection is not a function HOT 1
- Issues about "update" API in WebSocket / HTTP protocol with Meshblu 4.0.1 HOT 1
- Issues about "broadcast message" in WebSocket with Meshblu 4.0.1
- Issues about "subscribe" API in WebSocket with Meshblu 4.0.1 HOT 1
- Add optional support for Socket.io and Websockets
- Cannot receive message using "message.received" subscription
- Can get Devices use regex? HOT 1
- How to improve the amount of concurrency per second about Meshblu
- localhost 拒绝了我们的连接请求
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meshblu.