Sometimes a websocket message from Espruino WiFi is invalid UTF-8? Crashes the connection. #5771
Replies: 1 comment
-
Posted at 2017-06-12 by trusktr I'm not sure if this has anything to do with it, but I'm getting a bunch of errors in the Espruino console:
Posted at 2017-06-12 by trusktr It also seems like up until the this crash happens, the network responses take longer and longer until the crash. I'm keeping a running average, f.e. let ws = new WebSocket("ws://192.168.43.247/my_websocket", "protocolOne");
let lastTime = performance.now()
let timesCount = 0
let totalTime = 0
let averageTime = 0
ws.addEventListener('message', ({data}) => {
timesCount++
const thisTime = performance.now()
const elapsed = thisTime - lastTime
totalTime += elapsed
averageTime = totalTime / timesCount
lastTime = thisTime
mpuData = parseEspruinoJson(data)
});
ws.addEventListener('open', () => {
ws.send("Hello to Espruino!");
})
setInterval(() => console.log('avg time:', averageTime), 2000) and at first the average is about 38 ms for the time between responses, and by the time it crashes the running average is around 50 ms. It increases steadily the whole time. Posted at 2017-06-12 by @gfwilliams Yes, I'd totally sort out those other errors from the Espruino first.
Do you have I2C pullup resistors somewhere? I think I asked this on one of your other posts when you were getting the same error.
As in the other post, I think 16.6ms interval for sending data is just too fast. It totally explains the increasing delay for responses (as the buffer increases) and the out of memory error. When you get that error, execution gets interrupted, and I imagine it messes up the stream of data sent to the PC. Try it running at 30fps and see if you still get the error, then work back from there? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2017-06-12 by trusktr
Sometimes I receive the following error in Chrome when it is receiving websocket messages directly from Espruino WiFi:
I'm using the
ws
module for Espruino. Maybe there's something in that module that causes the websocket response to be invalid?What I'm trying to do in practice is read values from the
MPU6050
module, and send them through the websocket connection. Something like:Where
getMPU()
just return an MPU instance as per the MPU6050 docs, connected over I2C.So I have that
setInterval
loop that just continuously sends values over the websocket. The client code in Chrome does the following:Eventually, after a minute or two, I might get that error, and the connection breaks.
Beta Was this translation helpful? Give feedback.
All reactions