GithubHelp home page GithubHelp logo

esp32-tcpclient-to-websocket's Introduction

esp32-TCPclient-to-WebSocket

In Arduino IDE, the esp32 streams a small json from a Web socket and parses it. The values will be used to program a motor in a robot.

An issue I had was the node express Web socket was stringifying the json twice. I didn't realize that it "automatically" stringifies any json. So the deserialize function in the client still left me with a stringified json and did not throw an error, and would not yield the values. The stack and json questions are here:
bblanchon/ArduinoJson#1507 https://stackoverflow.com/questions/66283877/esp32-arduino-ide-web-socket-stream-json-no-errors-but-no-values

I recommend the Arduino Json Assistant and utilities for debugging
https://arduinojson.org/v6/assistant/

Stream utils
https://github.com/bblanchon/ArduinoStreamUtils
https://arduinojson.org/v6/how-to/debug-data-coming-from-a-stream/

Here's my working socket code from the server.js file of my node express Web server

// socket for esp32 to fetch projet data
var net = require('net');
var serverS = net.createServer(function(socket) {
	fs.readFile("./data/projet.json", 'utf-8', (err, data) => {
		if (err) {
			throw err;
		}
		socket.write(data); //<-- this used to be socket.write(JSON.stringify(data)) and didn't work
		socket.pipe(socket);
	});
	socket.on('end', () => {
		console.log('client disconnected');
	  });
});
serverS.on('error', (err) => {
	throw err;
  });
//console.log('socket listening on port...',1337);
serverS.listen(1337, () => {
	console.log('listening on port 1337...');
  });

esp32-tcpclient-to-websocket's People

Watchers

 avatar  avatar

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.