Skip to content
This repository was archived by the owner on Jan 29, 2018. It is now read-only.

Commit ebd13f0

Browse files
Implemented @Links2004 newline handling for ESP8266 websocket routing courtesy of Links2004/arduinoWebSockets#61
1 parent b2030e0 commit ebd13f0

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

ESP8266 Wifi Bridge/websocketserver.ino/websocketserver.ino.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class SerialTerminal {
5454
}
5555
}
5656

57+
5758
protected:
5859
uint8_t _buffer[1460];
5960
uint8_t * _bufferWritePtr;

public/js/esp8266.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ queryLoop = null;
33
var blocked;
44
var gcodeQueue; gcodeQueue = [];
55
var heap;
6+
var buffer = "";
67

78
function initEsp8266() {
89
$('#espConnectBtn').on('click', function() {
@@ -110,7 +111,7 @@ function startWS(url) {
110111
};
111112

112113
ws.onmessage = function(e){
113-
console.log(e.data)
114+
// console.log(e.data)
114115
var data = "";
115116
if(e.data instanceof ArrayBuffer){
116117
var bytes = new Uint8Array(e.data);
@@ -121,19 +122,28 @@ function startWS(url) {
121122
data = e.data;
122123
}
123124
// console.log(data);
124-
125125
$('#syncstatus').html('Socket OK');
126126
isConnected = true;
127-
if(data.indexOf("ok") != -1 || data == "start\r" || data.indexOf('<') == 0){
128-
if (data.indexOf("ok") == 0) { // Got an OK so we are clear to send
129-
printLog(data, '#cccccc', "wifi")
130-
uploadLine()
131-
} else if (data.indexOf('<') != -1) {
132-
updateStatus(data);
133-
} else {
134-
printLog(data, msgcolor, "wifi")
135-
}
136-
blocked = false;
127+
128+
buffer += data
129+
var split = buffer.split("\n");
130+
buffer = split.pop(); //last not fin data back to buffer
131+
// console.log(split)
132+
for (i=0; i< split.length; i++) {
133+
var response = split[i];
134+
console.log(response)
135+
// trigger line handling event here
136+
if(response.indexOf("ok") != -1 || response == "start\r" || response.indexOf('<') == 0){
137+
if (response.indexOf("ok") == 0) { // Got an OK so we are clear to send
138+
printLog(response, '#cccccc', "wifi")
139+
uploadLine()
140+
} else if (response.indexOf('<') != -1) {
141+
updateStatus(response);
142+
} else {
143+
printLog(response, msgcolor, "wifi")
144+
}
145+
blocked = false;
146+
}
137147
}
138148
};
139149
}

public/js/socketcomms.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ function initSocket() {
103103
}
104104

105105
function sendGcode(gcode) {
106+
// printLog("<i class='fa fa-arrow-right' aria-hidden='true'></i>"+ gcode, msgcolor)
106107
if(gcode) {
107108
// console.log('Sending', gcode)
108109
var connectVia = $('#connectVia').val()

0 commit comments

Comments
 (0)