Make library compatible with Particle devices

This commit is contained in:
CAOU123
2016-10-20 15:46:44 -04:00
parent 1defe6d8e1
commit 7810d0d0b3
8 changed files with 72 additions and 7 deletions

View File

@ -123,7 +123,7 @@ bool WebSockets::sendFrame(WSclient_t * client, WSopcode_t opcode, uint8_t * pay
#ifdef WEBSOCKETS_USE_BIG_MEM
// only for ESP since AVR has less HEAP
// try to send data in one TCP package (only if some free Heap is there)
if(!headerToPayload && ((length > 0) && (length < 1400)) && (ESP.getFreeHeap() > 6000)) {
if(!headerToPayload && ((length > 0) && (length < 1400)) && (GET_FREE_HEAP > 6000)) {
DEBUG_WEBSOCKETS("[WS][%d][sendFrame] pack to one TCP package...\n", client->num);
uint8_t * dataPtr = (uint8_t *) malloc(length + WEBSOCKETS_MAX_HEADER_SIZE);
if(dataPtr) {

View File

@ -25,7 +25,12 @@
#ifndef WEBSOCKETS_H_
#define WEBSOCKETS_H_
#ifdef STM32_DEVICE
#include <application.h>
#define bit(b) (1UL << (b)) // Taken directly from Arduino.h
#else
#include <Arduino.h>
#endif
//#define DEBUG_WEBSOCKETS(...) os_printf( __VA_ARGS__ )
@ -37,10 +42,17 @@
#ifdef ESP8266
#define WEBSOCKETS_MAX_DATA_SIZE (15*1024)
#define WEBSOCKETS_USE_BIG_MEM
#define GET_FREE_HEAP ESP.getFreeHeap()
#else
#ifdef STM32_DEVICE
#define WEBSOCKETS_MAX_DATA_SIZE (15*1024)
#define WEBSOCKETS_USE_BIG_MEM
#define GET_FREE_HEAP System.freeMemory()
#else
//atmega328p has only 2KB ram!
#define WEBSOCKETS_MAX_DATA_SIZE (1024)
#endif
#endif
#define WEBSOCKETS_TCP_TIMEOUT (2000)
@ -98,10 +110,15 @@
#elif (WEBSOCKETS_NETWORK_TYPE == NETWORK_W5100)
#ifdef STM32_DEVICE
#define WEBSOCKETS_NETWORK_CLASS TCPClient
#define WEBSOCKETS_NETWORK_SERVER_CLASS TCPServer
#else
#include <Ethernet.h>
#include <SPI.h>
#define WEBSOCKETS_NETWORK_CLASS EthernetClient
#define WEBSOCKETS_NETWORK_SERVER_CLASS EthernetServer
#endif
#elif (WEBSOCKETS_NETWORK_TYPE == NETWORK_ENC28J60)

View File

@ -443,7 +443,7 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
handshake += "\r\n";
client->tcp->write(handshake.c_str(), handshake.length());
client->tcp->write((uint8_t*)handshake.c_str(), handshake.length());
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
client->tcp->readStringUntil('\n', &(client->cHttpLine), std::bind(&WebSocketsClient::handleHeader, this, client, &(client->cHttpLine)));

View File

@ -25,7 +25,6 @@
#ifndef WEBSOCKETSCLIENT_H_
#define WEBSOCKETSCLIENT_H_
#include <Arduino.h>
#include "WebSockets.h"
class WebSocketsClient: private WebSockets {

View File

@ -739,20 +739,20 @@ void WebSocketsServer::handleHeader(WSclient_t * client, String * headerLine) {
"Connection: Upgrade\r\n"
"Sec-WebSocket-Version: 13\r\n"
"Sec-WebSocket-Accept: ");
client->tcp->write(sKey.c_str(), sKey.length());
client->tcp->write((uint8_t*)sKey.c_str(), sKey.length());
if(_origin.length() > 0) {
String origin = "\r\nAccess-Control-Allow-Origin: ";
origin += _origin;
origin += "\r\n";
client->tcp->write(origin.c_str(), origin.length());
client->tcp->write((uint8_t*)origin.c_str(), origin.length());
}
if(client->cProtocol.length() > 0) {
String protocol = "\r\nSec-WebSocket-Protocol: ";
protocol += _protocol;
protocol += "\r\n";
client->tcp->write(protocol.c_str(), protocol.length());
client->tcp->write((uint8_t*)protocol.c_str(), protocol.length());
} else {
client->tcp->write("\r\n");
}

View File

@ -25,7 +25,6 @@
#ifndef WEBSOCKETSSERVER_H_
#define WEBSOCKETSSERVER_H_
#include <Arduino.h>
#include "WebSockets.h"
#define WEBSOCKETS_SERVER_CLIENT_MAX (5)