This is just a test project for using websockets with a previous login. Most of the ideas are "borrwed" from this posts: https://auth0.com/blog/auth-with-socket-io/ The main difference is I'm not using Auth0 plataform to authenticate the user, just a local DB.
The idea for this project is to connect a Rasberry PI, equipped with environment sensors (temp, humidity, lighting, etc) and periodically send that info to a main server. The server should be able to manage multiple Pi's (there's the need for a login to identify each Pi) and store this info in a DB. Next step, would be that the server process the info and send action to the Pi's, like turn on/off a led.
#How does it work When the client wants to send info to the server.
- The client makes a HTTP request to the server, including login/password.
- The server check the credentials against the DB. If it's OK, it uses JWT to sign a token with the server info.
- The client gets the token and opens a websocket connection and emit an 'authenticate' event including the token.
- The server validates this token and uses the data in the token to identify the user.
- The server starts listening for sensor updates and updates the corresponding user data when this happens.
#How to run This has two parts: Server and Client. After installing the dependencies, just run:
node server.jscd clientnode client.js
The client is meant to run in a Pi, but it could be run in the same place as the server for testing propose. It's also equipped with a Sensor-mock module to simulate the Pi's sensors readings.