ekbduffy / spark_websockets Goto Github PK
View Code? Open in Web Editor NEWWebsockets implementation for Spark Core, ported from Arduino WebSocketClient
License: MIT License
Websockets implementation for Spark Core, ported from Arduino WebSocketClient
License: MIT License
The library hosted at Spark calls for
#include "websocketclient.h"
instead of
#include "Spark-Websockets.cpp"
In build.particle.io, I created a new app from the example test.cpp file. When I click Verify, I am presented with the following errors:
Code I am using:
// This #include statement was automatically added by the Particle IDE.
#include "Spark-Websockets/Spark-Websockets.h"
WebSocketClient client;
void onMessage(WebSocketClient client, char* message) {
Serial.print("Received: ");
Serial.println(message);
}
/* This function is called once at start up ----------------------------------*/
void setup()
{
Serial.begin(9600);
while(!Serial.available()); // Wait here until the user presses ENTER in the Serial Terminal
client.onMessage(onMessage);
client.connect("echo.websocket.org");
}
void loop()
{
client.monitor();
delay(3000);
client.send("Hello World!");
}
Any chance you plan to update the code (it currently doesn't seem to compile in the SparkCore Builder), and add it as a SparkCore Library (http://blog.spark.io/2014/05/27/flashing-firmware-with-spark-libraries/)?
I'm happy to help out, but I'm not sure what's required to fix things (ie. the base64Encode function is commented out).
Add alternative constructor allowing to specify IP instead of hostname or both (in case of both defined hostname is used only for headers sent - usefull for intranet servers)
sendHandshake should also include
WebSocketClientStringTable.replace("{2}", path);,
and WebSocketClientStringTable should have
"GET /{2} HTTP/1.1\x0d\x0a"
as the first line, in order for the path to work.
Hi,
it seems there is a problem with the GET request. My websocket server has the following URI:
ws://192.168.10.150/ExampleWebSocket/example.
When I put the code: client.connect("192.168.10.156",8080,"/ws","/ExampleWebSocket/example");
The GET request sniffed with Wireshark has GET / HTTP1.1 and not GET /ExampleWebSocket/example HTTP1.1
Can you fix it?
I am using version 0.0.5 of this library and when I want to connect with the echo server or my local websocket server I always get Connection Failed...
I'm seeing random hangs on the client during websocket communication between the core and node.js after sending 10-200 messages. I've tracked this down to the code that writes the NOOP bytes before printing the payload message to the client. I've done a tcpdump on this and it appears that for some reason the TCP send/ack sequence gets out of order, which causes the client to hang without disconnecting the socket first. Have you seen this issue before? Do you know of a workaround? I can provide you with the tcpdump output if you'd like.
Another tangentially related question: The version of Spark-Websockets published via the Spark web IDE is different from master in your git repository. Should I be using the published version or the master version in git? For what it's worth, I've tried both and had the same result.
Thanks for any help.
Veryfing code using this library in Particle Build fails with this error:
Spark-Websockets/Spark-Websockets.h:72:3: error: 'byte' does not name a type
byte _opCode
Trying to compile the example app inside of the web ide and this error happens
bool result = true;
shouldn't it be initialized to false?
Hey @ekbduffy - thanks for the lib and contribution. Missing a set of parentheses in the example file after the include that doesn't allow the firmware to compile.
I try to compile the example sketch but I get these errors on Spark Build:
In file included from ../inc/spark_wiring.h:30:0,
from ../inc/application.h:29,
from pushbullet_notifications.cpp:2:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
pushbullet_notifications.cpp:3:16: error: variable or field 'onMessage' declared void
void onMessage(WebSocketClient client, char* message);
^
pushbullet_notifications.cpp:3:16: error: 'WebSocketClient' was not declared in this scope
pushbullet_notifications.cpp:3:40: error: expected primary-expression before 'char'
void onMessage(WebSocketClient client, char* message);
^
make: *** [pushbullet_notifications.o] Error 1
When trying the example the websocket does not function. Here is the output of the Photon serial connection:
Connecting...
Connected, sending handshake.
Sending handshake!
GET / HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: echo.websocket.org:80
Origin: SparkWebSocketClient
Sec-WebSocket-Key: 1VTFj/CydlBCZDucDqw8eA==
Sec-WebSocket-Version: 13
Handshake sent
Reading handshake!
handshake rcvd line: HTTP/1.1 101 Web Socket Protocol Handshake
handshake rcvd line: Access-Control-Allow-Credentials: true
handshake rcvd line: Access-Control-Allow-Headers: content-type
handshake rcvd line: Access-Control-Allow-Headers: authorization
handshake rcvd line: Access-Control-Allow-Headers: x-websocket-extensions
handshake rcvd line: Access-Control-Allow-Headers: x-websocket-version
handshake rcvd line: Access-Control-Allow-Headers: x-websocket-protocol
handshake rcvd line: Access-Control-Allow-Origin: SparkWebSocketClient
handshake rcvd line: Connection: Upgrade
handshake rcvd line: Date: Sat, 18 Jul 2015 02:48:22 GMT
handshake rcvd line: Sec-WebSocket-Accept: kuZ2KVbyl4oJOyuTXN/B93O3z9Y=
handshake rcvd line: Server: Kaazing Gateway
handshake rcvd line: Upgrade: websocket
handshake rcvd line:
Handshake Failed! Terminating
Connection Failed!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.