Da Laser BACK END BABY

We need to build that back end baby. The butt so to speak. Where the action BE AT.

The idea is to have collaborative aiming of our laser across the internet.

Check it out https://github.com/ishmandoo/laser

So we’re gonna docker this. Because we’re off the goddamn chain.

Ben already has some code on his github

https://github.com/ishmandoo/multiplayer_test

That we’re going to modify to our needs. He essentially used

http://socket.io/get-started/chat/ as a base level + some basic docker

So this already does what we need it to do basically. Just change the name of the git repository and it’ll boot up the server.

check this out https://www.digitalocean.com/community/tutorials/docker-explained-using-dockerfiles-to-automate-building-of-images for more deets.

“I built it with  “docker build -t laser .”
and ran it with “docker run -d -p 80:3000 laser””- Ben

Okay, also technically we need a front end too, so

https://developer.mozilla.org/en-US/docs/Web/API/Touch_events#Create_a_canvas

duct taped together with the chat application and http://stackoverflow.com/questions/4037212/html-canvas-full-screen full screening.

We just need to tell the server when touch is down and where. We normalized x and y to be ratios of 0-1 fractions across the screen. It seems we can’t rely on not going a little over 1 maybe so be aware.

The Socket.io part is very straightforward.

The express stuffjust serves the ordinary webpages. (app.get)

The only thing kind of funky is storing data associated with each client. We just attach it to the socket object, which should be self cleaning to some degree. We also add a timeout just in case we somehow lose a touch end. Maybe unneccessary.

Polling the path /location will return json of the average position of everyone touching the screen.

All in all pretty straightforward. And it seems to work with our phones. Except not Beth.

Now onto the microcontroller code. Should be simple, but for some reason is not. We have to glue together a couple of things if we want to bolt the arduino to an esp8266. Alternatives are to go native on an esp8266 or use a Photon. It is bizarre to me that one of these is not a clear winner. Why is it not so incredibly easy to make http requests on the Photon?

Also, a comment: Being name the photon makes it impossible to search for you. It sounds cool, but it’s a bad name.

Leave a Reply

Your email address will not be published. Required fields are marked *