Giter Club home page Giter Club logo

Comments (4)

dimonomid avatar dimonomid commented on July 22, 2024

@aifer2007 , could you please also share the code which sends the data? So that I can reproduce the issue easily.

from mjs.

aifer2007 avatar aifer2007 commented on July 22, 2024

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.

dimonomid avatar dimonomid commented on July 22, 2024

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.

dimonomid avatar dimonomid commented on July 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.