Git Product home page Git Product logo

microblu_ws's Introduction

#SKYNET MAIN HAS TRANSITIONED TO SOCKETIO 1.0, making this repo no longer functional. We may update in the future but for now please see our new MQTT client https://github.com/skynetim/skynetos_mqtt

 SSSSS  kk                            tt
SS      kk  kk yy   yy nn nnn    eee  tt
 SSSSS  kkkkk  yy   yy nnn  nn ee   e tttt
     SS kk kk   yyyyyy nn   nn eeeee  tt
 SSSSS  kk  kk      yy nn   nn  eeeee  tttt
                yyyyy

Skynet OS allows you to connect to Skynet.im via your Arduino and an Arduino ethernet or wifi shield (or any other device that properly implements the Client interface)

##Videos

##Install

  • Clone or download and unzip.
  • Rename the resulting folder to remove any - characters, and import library via Arduino menu Sketch->Import Library->Add Library
  • After adding, you'll find File->Examples->SkynetClient

##Examples Find full examples in the File->Examples->SkynetClient menu but generally, theres 3 ways to use: onMessage, log message, or bind. ###onMessage The simplest method is to register a function to be called when Skynet receives a message for your device:

void setup()
{
  //...
  skynetclient.setMessageDelegate(onMessage);
}
void loop(){
  skynetclient.monitor();
}

Then you can do whatever you want with that message. You can even grab a third party json parser, here we print it to console:

void onMessage(const char * const data) {

  Serial.print("Parse: ");
  Serial.println(data);

}

###Log Even simpler than that is to just send data to Skynet with the logMessage command:

void loop(){
  //Craft a string with your data like "light":"423","temp":"356"
  skynetclient.logMessage(message);
}

Now you can subscribe to your data elsewhere. See the api page for rest examples with Rest, Javascript, and more! http://skynet.im/#api ###Bind Lastly, we've created the ability to bind 2 devices to just Skynet like a virtual serial cable. This is good for passing lots of information between devices without all the addressing overhead. You can read the data out of the Skynet Client just like a Serial device:

void loop() {
  skynetclient.monitor();
  while(skynetclient.available())
  	Serial.print(skynetclient.read());
}

This can be seen in our Firmata sketch paired with the Node example in the node_client directory. (see also: https://www.npmjs.org/package/skynet-serial) NOTE: This sketch requires the new Arduino 1.5 IDE! http://arduino.cc/en/main/software

LICENSE

(LGPL License)

Copyright (c) 2014 Octoblu [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

microblu_ws's People

Contributors

jacobrosenthal avatar chrismatthieu avatar monteslu avatar

Stargazers

₴Ⱡ33₱ avatar Angus H. avatar  avatar Carlos Medrano avatar  avatar Pathompong Puengrostham avatar Dhi Aurrahman avatar Michael Christenson II avatar  avatar Moheeb Zara avatar dap avatar Rick Carlino avatar

Watchers

Josh avatar  avatar  avatar Koshin Mariano avatar James Bulpin avatar cmw avatar James Cloos avatar Moheeb Zara avatar Stephen Saunders avatar Geir Ramleth avatar Alisa Palson avatar Aaron Herres avatar  avatar  avatar LeRoy Miller avatar  avatar Cody Matthieu avatar Detroit Thomas avatar Andrew Steinheiser avatar Square Root of Saturn avatar Jason Wiram avatar  avatar

microblu_ws's Issues

TCP Failed

It often takes 2 minutes of failed TCP attempts for skynet to respond. Since it seems fairly consistant I think it might have something to do with a connection that needs to timeout on the skynet side before our new connection is accepted. This rears its head for instance right after you plug in or program an arduino and click the Serial monitor button. Its already been connected to skynet, and by clicking the monitor you reset that process and start again, possibly leaving an open socket or something?

Connecting TCP
TCP Failed
Connecting TCP
TCP Failed
Connecting TCP
TCP Failed
Connecting TCP
HTTP/1.1 200 OK
Content-Type: text/plain
Date: Sun, 27 Apr 2014 04:38:12 GMT
Connection: keep-alive
Transfer-Encoding: chunked

47
XXXXX:60:60:websocket,htmlfile,xhr-polling,jsonp-polling
SID: XXXXX
HTTP/1.1 101 Web Socket Protocol Handshake
Websocket Connected
Upgrade: WebSocket
Connection: Upgrade
WebSocket-Origin: undefined
WebSocket-Location: ws://skynet.im/socket.io/1/websocket/XXXXX

1::
Socket Connect
5:::{"name":"identify","args":[{"socketid":"XXXXX"}]}
Message
identify
Sending: �5:::{"name":"identity","args":[{"socketid":"XXXXX", "uuid":"XXXXX", "token":"XXXXX"}]}ˇ
5:::{"name":"ready","args":[{"api":"connect","status":201,"socketid":"XXXXX","uuid":"XXXXX","token":"XXXXX"}]}
Message
ready
Skynet Connect
no uuid refresh necessary
no token refresh necessary
Connected!
uuid: XXXXX
token: XXXXX

cc3000 sketch stops after about 2 minutes

Im tracking an issue when having the cc3000 send websocket data every second in order to measure up time. After often exactly 129 requests, though Ive also seen 131, the code freezes up. Im relatively confident its not in the skynet code as we have devices with approaching a week of uptime.

Ive checked memory with

int freeRam () {
  extern int __heap_start, *__brkval; 
  int v; 
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
}

and that stays constant so I dont think its a leak. Ive also tried cooling the device directly in front of a fan, so I dont think its a overheating issue..

Find a json parser (as opposed to tokenizer) that doesn't use dynamic memory

We're using jsmn right now for tokenizing. Previously I hadn't found a good parser yet that doesn't use dynamic memory or a ton of it. However just tokenizing means we don't respect JSONs requirement that keys are unordered. We haven't seen this happen yet, but what we have seen several times is API changes to add or remove a set of keys which changes the tokenizer indexes.

We've made memory improvements that mean we can probably afford a parser so we just need to find (or write) one.

handle forwarding serial data without binding

after issue #6 is complete, incoming json message should be able to route base64 firmata data inside of a message payload. This will enable a single skynet device to control multiple firmware devices.

Occasional freezing on identify

No idea what this is yet. From our point of view we connect properly 90% of time, so I dont think its in the C code. I think its traffic or some other bug related on the server side.

Connecting TCP
HTTP/1.1 200 OK
Content-Type: text/plain
Date: Sun, 27 Apr 2014 03:46:58 GMT
Connection: keep-alive
Transfer-Encoding: chunked

47
wddXSiZkXy1_oHS7Wc0l:60:60:websocket,htmlfile,xhr-polling,jsonp-polling
SID: wddXSiZkXy1_oHS7Wc0l
HTTP/1.1 101 Web Socket Protocol Handshake
Websocket Connected
Upgrade: WebSocket
Connection: Upgrade
WebSocket-Origin: undefined
WebSocket-Location: ws://skynet.im/socket.io/1/websocket/wddXSiZkXy1_oHS7Wc0l

1::
Socket Connect
5:::{"name":"identify","args":[{"socketid":"XXXX"}]}
Message
identify
Sending: �5:::{"name":"identity","args":[{"socketid":"XXX", "uuid":"XXXXXX", "token":"XXXXX"}]}ˇ

The only fix from our side is a watchdog or some other timeout mechanism to rescue us from freezes like these...

Bad request

i am trying to test my own private cloud with skynet.im
I am using skynetim_echo just to test the connection, but i get the following response:

Connecting TCP
POST /socket.io/1 HTTP/1.1
Host: 192.168.1.43

HTTP/1.1 400 Bad Request
No Initial Ok response

Maybe something wrong on server? any clue o this?

Resets or freezes - RAM Shortages

Theres only 2k sram on a modern arduino Uno
http://arduino.cc/en/Main/arduinoBoardUno

actually something like 1824 bytes available in a blank sketch
http://playground.arduino.cc/Code/AvailableMemory

That space mainly goes to variables in use while running.

The biggest use is string data. Every character is a byte.

I have 115 or so more bytes used by text (like skynet defines, etc) need to find a way to store this in program memory
http://arduino.cc/en/Reference/PROGMEM

Another 100 or so bytes for the uuid, token and socket, mac address. Clear uuid and token after writing to eeprom?

Then lets talk about buffers.

The aJson library wants 256 byte buffer (we could manually limit that down to our biggest msg maybe. Lets examine:

I think our biggest skynet message, besides data is 180 bytes so thats our minimum
{"name":"ready","args":[{"api":"connect","status":201,"socketid":"MVxy-byDx8d3z_dVr-PS","uuid":"ed4bfc41-9acd-11e3-9550-cdad95b33498","token":"qezh4s4laxmndn29c50fykaqbqaxajor"}]}

a data package is currently 129 chars without payload,

{"name":"message","args":["ed4bfc41-9acd-11e3-9550-cdad95b33498",{"data":"","fromUuid":"a89a0910-9b46-11e3-af21-030ff142869f"}]}

so wed only have maybe 50 bytes for data, which maybe isnt idea. Frankly those extra bytes up to 256 look pretty good as they get us up to almost 50% payload per packet

Socketio work needs 50 bytes buffer for its largest message. Probably could shave that down to nothing by parsing by character. Future work.

Beautifully, Arduino 1.5 will actually tell you how much you're using (though not while live)

So on an Uno
Sketch uses 25,814 bytes (80%) of program storage space. Maximum is 32,256 bytes.
Global variables use 1,373 bytes (67%) of dynamic memory, leaving 675 bytes for local variables. Maximum is 2,048 bytes.

And as soon as sketch tries to hit ethernet connection, It dies :(

and thats before firmata.
Firmata has done a nice ram writeup on their project:
firmata/arduino#81

up to 800 bytes with everything on, not including anything about ethernet!

So as we can see its very hard to get us on the UNO.

So other arduino options. Mega has 8k! Currently targeting there
http://arduino.cc/en/Main/arduinoBoardMega

Sketch uses 27,038 bytes (10%) of program storage space. Maximum is 258,048 bytes.
Global variables use 1,859 bytes (22%) of dynamic memory, leaving 6,333 bytes for local variables. Maximum is 8,192 bytes.

Sparkcore has 20KB ! So I think we might want to target that part long term.

Websocket version target?

not presenting a websocket version

client.print(F("GET /socket.io/1/websocket/"));
client.print(sid);
client.println(F(" HTTP/1.1"));
client.print(F("Host: "));
client.println(hostname);
client.println(F("Origin: ArduinoSkynetClient"));
client.println(F("Upgrade: WebSocket"));    // must be camelcase ?!
client.println(F("Connection: Upgrade\r\n"));

we could for instance send and look exactly like a socketio client

client.print(F("GET /socket.io/1/websocket/"));
client.print(sid);
client.print(F(" HTTP/1.1\r\n"));
client.print(F("Connection: Upgrade\r\n"));
client.print(F("Upgrade: websocket\r\n"));

client.print(F("Host: "));
client.print(hostname);
client.print("\r\n");
client.print(F("Origin: ArduinoSkynetClient\r\n"));
client.print(F("Sec-WebSocket-Version: 13\r\n"));
client.print(F("Sec-WebSocket-Key: MTMtMTM2MDEzNjYxNzMxOA==\r\n\r\n")); 

But we'd have to fake Sec-WebSocket-Key unles we want to do a random number generation and base 64 encoding etc.

Any reason we need to implement?

Support cc3000 shields like Adafruit Wifi

Ideally wed LOVE to support cc3000 solutions like Spark, adafruit wifi shield, etc.

The problem is the main firmware out there is adafruit's and sadly theirs does not conform to Client, which is the standard Arduino TCP interface that we (and Arduino) use.

Sadly this is not development they've been interested in doing 'in house' so far.
adafruit/Adafruit_CC3000_Library#70
adafruit/Adafruit_CC3000_Library#25

Its possible to fork our codebase pretty heavily, but doesn't seem worth it at this time when the end goal should probably be cc3000 libraries support the Client standard.

One glimmer of hope is the Spark. They use the CC3000 and actually have implemented a Client conforming interface which we've successfully tested with some hacked together code:
https://www.youtube.com/watch?v=CBGIolfwqgw&list=UUBMdqdAbjJjE9LvMjVpiwUw

Its probably best to see what someone can move over from there first.
https://github.com/spark/core-firmware/blob/master/src/spark_wiring_tcpclient.cpp

Code duplication in connect

Need to unduplicate connect. The reason for the duplication is that depending on the incoming client's library so resolving a host to IP address is vastly different or unsupported...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.