Comments (4)
@aifer2007 , could you please also share the code which sends the data? So that I can reproduce the issue easily.
from mjs.
Yes, thanks.
Nodejs code here:
var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort("/dev/tty.usbserial-A94JN1PL", {
baudrate: 115200, autoOpen: false,
});
serialPort.open(function (error) {
if ( error ) {
console.log('failed to open: '+error);
} else {
console.log('open');
serialPort.on('data', function(data) {
console.log('data received: ' + data);
if(data.indexOf('talkstart')> -1) {
let vd = "1234567890123456789012345678901234567890123456";
console.log("data packet len: " + vd.length);
let pktNum = 0;
let id = setInterval(function(){
serialPort.write(vd, function(err, results) {
if(err) {
console.log('err ' + err);
} else {
pktNum++;
if(pktNum>499) clearInterval(id);
}
});
}, 20); // 46bytes/20ms, 23000 bytes total
}
});
}
});
from mjs.
Honestly, failed to reproduce. I used your scripts, and the only (seemingly unrelated) modification I had to do is the following: since I upload init.js
to the device and restart it with the following command:
mos put init.js && mos call Sys.Reboot && mos console
we shouldn't emit go
in the beginning of device execution, because that could lead to multiple go
being emitted (the first one could be emitted right before device reboot), so node script starts two sequences of data. So I emit go
after 2 seconds.
All in all, here are the scripts I use:
init.js
on esp32:
// Load Mongoose OS API
load('api_timer.js');
load('api_uart.js');
load('api_sys.js');
let rxAcc = ""; // to store all the bytes received
let rx_total = 0; // total number of received bytes
// Configure UART at 115200 baud
UART.setConfig(1,{
baudRate: 115200,
});
UART.setDispatcher(1, function(uartNo, ud) {
let ra = UART.readAvail(uartNo);
if (ra > 0) {
let data = UART.read(uartNo);
rxAcc += data;
rx_total += data.length;
print("len:", data.length, "total:", rx_total);
}
}, null);
// Enable Rx
UART.setRxEnabled(1, true);
// Start communication after 2 seconds
Timer.set(2000 /* milliseconds */, false /* repeat */, function() {
// signal, a nodejs serialport connected to EPS32 will start sending data
UART.write(1,"go");
}, null);
Timer.set(17000 /* milliseconds */, false /* repeat */, function() {
print("==================");
print("rxAcc lent:", rxAcc.length, "rx_total:", rx_total);
}, null);
Node.js script:
'use strict';
var SerialPort = require("serialport")
var serialPort = new SerialPort("/dev/ttyUSB1", {
baudRate: 115200, autoOpen: false,
});
serialPort.open(function (error) {
if ( error ) {
console.log('failed to open: '+error);
} else {
console.log('open');
serialPort.on('data', function(data) {
console.log('data received: ' + data);
if(data.indexOf('go')> -1) {
let vd = "1234567890123456789012345678901234567890123456";
console.log("data packet len: " + vd.length);
let pktNum = 0;
let id = setInterval(function(){
serialPort.write(vd, function(err, results) {
if(err) {
console.log('err ' + err);
} else {
pktNum++;
if(pktNum>499) clearInterval(id);
}
});
}, 20); // 46bytes/20ms, 23000 bytes total
}
});
}
});
In the end, device always prints:
==================
rxAcc lent: 23000 rx_total: 23000
from mjs.
Closing this one. If you believe that the issue is still here, feel free to provide more details and reopen.
from mjs.
Related Issues (20)
- Assertion `userdata_idx > 0' failed at src/mjs_ffi.c:560: ffi_fn_t *get_cb_impl_by_signature(const mjs_ffi_sig_t *)
- Assertion `ctx->frame == NULL' failed at src/mjs_json.c:406: void frozen_cb(void *, const char *, size_t, const char *, const struct json_token *)
- SEGV src/mjs_ffi.c:456 in ffi_cb_impl_wpwwwww
- SEGV src/mjs_ffi.c:982:24 in mjs_ffi_cb_free
- SEGV src/mjs_gc.c:190:11 in gc_sweep
- SEGV
- Invalid memory read in mjs_execute() at mjs.c:9320 HOT 1
- Heap buffer overflow in mjs_mk_string() at mjs.c:13671
- Segmentation fault in mjs_exec.c:880
- stack-overflow onpnext
- stack-overflow in parse_call_dot_mem
- SEGV in exec_expr
- SEGV in mjs_parse_ffi_signature
- Function Pointer Hijack mjs/mjs.c in mjs_execute HOT 1
- SEGV in mjs_getretvalpos
- SEGV (/mjs/mjs+0x4ec508)
- SegFaultOnPc in mjs_destroy() at mjs.c:7563
- Segmentation Fault in getprop_builtin_foreign HOT 1
- stack-overflow in mjs_op_json_stringify() at mjs.c:11362
- SEGV in mjs_op_json_parse() at mjs.c:11364
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mjs.