Skip to content

hpssjellis/Particle-Spark-Core-Photon-Websocket-Hack

 
 

Repository files navigation

Node.js Websocket Test

update May 2021 Using Gitpod

Login to Github then right-click this link --> open in new window (So it can process while you do other stuff)

https://gitpod.io/#github.com/hpssjellis/Particle-Spark-Core-Photon-Websocket-Hack

Then

npm install

Open Browser window

And presto you are in the WebApp that students did very early in the year.


note Sept 16, 2019

particle has deprecated this

https://api.spark.io/v1/devices

and it should be changed to

https://api.particle.io/v1/devices

The index.html web page MUST be generated by the nodejs server.js file or it will not connect with the socket.ino program flashed to your Photon.

https://www.youtube.com/watch?v=zRZJHMFL0p4

April 29th, 2019. Great news. I just got this working on repl.it

I just needed to change "server.js" to "index.js"

This is really good news as cloud9 is shutting down in June 2019 and becoming AWS cloud9 which has a much more advanced payment process and honestly completely confuses me.

repl.it seems much more like the original cloud9 and seems to be free.

..

.

Particle.io Websockets for the Photon

May 15, 2017 I have been looking into several ways to make the webpage more secure, but each method adds bulk and confusion to the simple process. I think perhaps the best method is to limit the number of chat connections to 2 if a photon and webserver or 3 if two photons etc. That way other people will not be able to snoop on your connections and if they are snooping then you can't connect


Note: This is for very fast communication with the Particle.io Photon and only sends one BYTE at a time in Ascii format A B C D ... or a b c d ... and other ascii characters. This should give 255 seperate commands to control your device.

Note every 12 seconds it sends the command "C" which checks if the connection is still alive and dims the main LED

updated May 3rd, 2017

typically about 7 ms delay. should be very good for fast communication with the Photon

On a private server remember to give people access to your application. On a public server that is not an issue

Just got send working so now the photon can receive Ascii instructions and send ascii instruction (255 commands)

OK security activating the photon. Security needs to improve with the website after connection is achieved.

Use at your own risk.

update Mar 28, 2017

Briefly it was not working, seems to be working now.

Load socket.ino onto the photon (wait 25 s for D7 to go out)

can use putty to monitor the serial connection.

run server.js using node js. (auto installation by running npm install)

using your node js server open index.html, enter ID and access code then click connect (uses the cloud to connect the websocket)

Then try the websocket commands can use any single character (case sensitive so should have 255 possible commands) click the A button to light D7, the B button to turn off D7

Regualr cloud commands average at about 1200 ms these commands average about 10 ms.

If the above works try the carsocket.ino and car-control.html pages for controlling a toy car.

.

.

.

.

.

Originally a tiny demo using the einaros/ws WebSockets implementation.

I have changed this demo to work with the Spark Core. Flash the .ino file onto your spark core and then load this github site onto a cloud9 server. The web page buttons should activate the D7 LED on the spark core.

Note: the "connect" function will have to be activated to get the Particle.io Photon (formerly Spark.io Core) ready to recieive websocket style information.

Updated Oct4, 2015. My bad, I should have given a method to activatet the connect function. I have added a new webpage called activation.html, which needs your core ID and access Token and then click the button "connect" before the Photon can talk to your nodeJs server.

#running on Cloud9 http://c9.io make a login Create A new NODEJS workspace Clone from URL https://github.com/hpssjellis/Particle-Spark-Core-Photon-Websocket-Hack.git

Open a terminal npm install

right click on the server.js file run

main menu --> preview --> preview running app

This will load the connection page but you will have to first load activation.html

Note. Users will have to run activation.html to enter their photon ID and access code before any of this will work. Then you can click the connect button to load the main index.html page that communicates with the photon

.

.

.

.

.

.

.

.

From the original Github heroku-examples/node-ws-test

Running Locally

npm install
npm start

Running on Heroku

heroku create
git push heroku master
heroku open

To see a full discussion of this process check out the forum at https://community.particle.io/t/tcp-server-and-client-example-socket-programs-d7-on-please/11307

Note: Use at your own risk.

About

A tiny demo using the einaros/ws WebSockets implementation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 40.2%
  • JavaScript 30.3%
  • C++ 29.5%