Community
cancel
Showing results for 
Search instead for 
Did you mean: 
idata
Community Manager
1,141 Views

Issue about console.log in Node.JS and memory of Intel Edison

Hello!

Now in prototype we use Intel Edison as gateway for our system (from UART 921600 to TCP socket). And now we have some strange issue about Edison's working. The Edison works well durin 1 day, after that - it's down, and have no ability connect over Wi-Fi, even Intel XDK. Helps ony firmware new Yocto image, I realized what I give now incomplete information but I have some thougths about what situation.

In own code there are a lot of console.log outputs (for each UART packet on speed 1 Mbps). Is it may be a reason for stucking of the Edison?

By the way - where is exist output of console.log() - in RAM or ROM?

There is my code (some console.log was commented for tests)

/*jslint node:true, vars:true, bitwise:true, unparam:true */

/*jshint unused:true */

/*

app_EdisonSocket is purposed to for enabling transparent bridge for UART1 over WiFi using TCP.

On clients part (balalaika.local:3000) there is some features:

- set UART speed

- enable/disable logging

- visualise connected clients

*/

/* Definitions */

var UART_SPEED = 921600;

var HTTP_PORT = 3000;

var TCP_PORT = 56789;

var timerId = setInterval(function() {

console.log("This is log console. We are testing overflow of the disk. 123453345767597807iutkmhbWETY 3Q5UYHE4T5UYHQ4EA35T6YUHQ4RA65TUYH4AQR65JUHR4AJURA5YJARTJUY");

}, 100);

/* Imports */

var mraa = require('mraa'); //require mraa

console.log('MRAA Version: ' + mraa.getVersion());

//Init UART1

var u = new mraa.Uart(0);

var serialPath = u.getDevicePath();

var SerialPort = require("serialport");

var serialPort = new SerialPort(

serialPath,

{

baudrate: UART_SPEED

}

);

//TCP Server

var net = require('net');

var tcpServer = net.createServer();

var tcpClients = [];

tcpServer.listen(TCP_PORT, function() {

console.log("TCP Server start listening on %j", tcpServer.address());

});

tcpServer.on("connection", handleConnection);

function handleConnection(conn) {

var remoteAddress = conn.remoteAddress + ":" + conn.remotePort;

console.log("New client connection from %s", remoteAddress);

io.emit('log message', {value: "Connection open", userId: remoteAddress});

tcpClients.push(conn);

conn.on("data", onConnData);

conn.once("close", onConnClose);

conn.on("error", onConnError);

function onConnData(message) {

var sendBuf = new Buffer(message);

serialPort.write(sendBuf);

//console.log('Connection data from ', remoteAddress, ": ", sendBuf);

io.emit('log message', {value: sendBuf.toString('hex'), userId: remoteAddress});

}

function onConnClose() {

console.log('Connection from %s closed', remoteAddress);

io.emit('log message', {value: "Connection closed", userId: remoteAddress});

tcpClients.splice(tcpClients.indexOf(conn), 1);

}

function onConnError(err) {

console.log('Connection %s error: %s', remoteAddress, err.message);

io.emit('log message', {value: "Connection error: " + err.message, userId: remoteAddress});

}

}

function broadcast(message) {

io.emit('log message', {value: message.toString('hex'), userId: "UART1"});

tcpClients.forEach(function (tcpClient) {

tcpClient.write(message);

});

}

//HTTP server init

var express = require('express');

var app = express();

var path = require('path');

var http = require('http').Server(app);

var io = require('socket.io')(http);

// HTTP Port start listening

http.listen(HTTP_PORT, function() {

var address = http.address();

var port = address.port;

console.log("HTTP listen on port " + port);

//LCD_updateHttp(port);

});

var connectedUsersArray = [];

var userId;

app.get('/', function(req, res) {

//Join all arguments together and normalize the resulting path.

res.sendFile(path.join(__dirname + '/client', 'index.html'));

});

//Allow use of files in client folder

app.use(express.static(__dirname + '/client'));

app.use('/client', express.static(__dirname + '/client'));

//Socket.io Event handlers

io.on('connection', function(socket) {

console.log("\n Add new User: u"+connectedUsersArray.length);

if(connectedUsersArray.length > 0) {

var element = connectedUsersArray[connectedUsersArray.length-1];

userId = 'u' + (parseInt(element.replace("u", ""))+1);

}

else {

userId = "u0";

}

console.log('a user connected: '+userId);

io.emit('user connect', userId);

connectedUsersArray.push(userId);

console.log('Number of Users Connected ' + connectedUsersArray.length);

console.log('User(s) Connected: ' + connectedUsersArray);

io.emit('connected users', connectedUsersArray);

socket.on('user disconnect', function(msg) {

console.log('remove: ' + msg);

connectedUsersArray.splice(connectedUsersArray.lastIndexOf(msg), 1);

io.emit('user disconnect', msg);

});

socket.on('log message', function(msg) {

io.emit('log message', msg);

//console.log('message: ' + msg.value);

});

socket.on("change uart speed", function(newSpeed) {

console.log("Invoke speed change to " + newSpeed);

serialPort.update(

{

baudrate: newSpeed

}

);

io.emit('log message', {value: "UART Speed changed to " + newSpeed, userId: "UART1"});

});

});

serialPort.on("open", function() {

console.log("UART opened and connected to " +serialPath);

//If we get data on UART then resend it to all connected users

serialPort.on("data", function(data) {

var rxBuf = new Buffer(data);

//console.log("Data received from UART: ", rxBuf);

broadcast(rxBuf);

});

});

0 Kudos
7 Replies
idata
Community Manager
62 Views

Hi Danil Borchevkin,

 

 

Thanks for your interest in the Intel Edison Platform.

 

 

It is strange that now your Edison is not working.

 

 

Have you try flashing again your image?

 

 

Also could you tell me which image are you using? (Use the command configure_edison --version)

 

 

Have a nice day!

 

 

Best Regards,

 

-Jose.
idata
Community Manager
62 Views

When I try get out of configure_edison --version I received None - this is strange because I use latest image (check by Windows setup utility for Edison)

Yes, after reflashing the Edison work well till new stuck.

idata
Community Manager
62 Views

Hi Danil Borchevkin,

I'm sorry in the latest firmware to acquire the version of it, you have to use the command: cat /etc/version.

Now when you say: "work well till new stuck". Do you mean that is working well? Or do you have the same issue again?

I will be waiting for your reply, have a nice day!

Best Regards,

 

-Jose.
idata
Community Manager
62 Views

"Work well" I mean what Edison works well during ~1 day. After - I have new stuck whick can be fix only reflashing.

idata
Community Manager
62 Views

Hi Danil Borchevkin,

 

 

Have you try reducing your message console outputs? Maybe you are right and you are stocking the Edison by sending a lot of messages through UART.

 

 

Have a nice day!

 

 

Best Regards,

 

-Jose.
idata
Community Manager
62 Views

Yes I reducing amount of console.log() and problem was fixed.

So right answer - a lot of console out events may be a reason of the Edison "freeze"

idata
Community Manager
62 Views

Hi Danil Borchevkin,

 

 

I'm glad to hear that the issue is fix!

 

 

If you have any more questions, please don't hesitate to ask.

 

 

Best Regards,

 

-Jose.
Reply