I'm trying to send data from my ESP8266 to a NodeJS TCP server, the connection and basic charakters (48-90) are working fine, but if I use others like ASCII-Code (0,1,2,3...) I don't get any usefull data out of it. So what I was thinking about that there are some character which aren't allowed to send over TCP/IP.
By the way, I'm using this to write to the server, and I work with the standard WiFi Client library
char arr[255]
for(int i = 0; i < 255; i++){
arr[i] = (char)i;
}
client.print(arr);
Nodejs File:
// Load the TCP Library
net = require('net');
var mysql = require('mysql');
// Keep track of the chat clients
var clients = [];
var uploadCounter = 0;
initMySQLConnection();
// Start a TCP Server
net.createServer(function (socket) {
// Identify this client
socket.name = socket.remoteAddress + ":" + socket.remotePort
// Put this new client in the list
clients.push(socket);
// Send a nice welcome message and announce
socket.write("Welcome " + socket.name + "\n");
broadcast(socket.name + " connected\n", socket);
// Handle incoming messages from clients.
socket.on('data', function (data) {
broadcast(">> " + data, socket);
uploadData(data);
});
// Remove the client from the list when it leaves
socket.on('end', function () {
clients.splice(clients.indexOf(socket), 1);
broadcast(socket.name + " disconnected.\n\n");
});
// Send a message to all clients
function broadcast(message, sender) {
clients.forEach(function (client) {
// Don't want to send it to sender
if (client === sender) return;
//client.write(message);
});
// Log it to the server output too
process.stdout.write(message)
}
}).listen(10101);
// Put a friendly message on the terminal of the server.
console.log("Chat server running at port 10101\n");
var connection;
function initMySQLConnection() {
connection = mysql.createConnection({
host: "host",
user: "user",
password: "pass",
database: "database"
});
connection.connect(function (err) {
if (err) {
console.log('error when connecting to db:', err);
}
});
connection.on('error', function (err) {
console.log('db error', err);
if (err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually
// lost due to either server restart, or a
} else { // connnection idle timeout (the wait_timeout
throw err; // server variable configures this)
}
});
setInterval(function () {
connection.query('SELECT 1');
}, 60000);
}
function uploadData(data) {
data = String(data);
console.log("Package Length: " + data.length);
console.log("GOT ASCII CODE: ");
for (var i = 0; i < 255; i++) {
console.log(data.charCodeAt(i));
}
//upload Code
}
I don't get any usefull data out of it
................ what are you expecting forASCII-Code (0,1,2,3...)
?