0

I have found some node.js code for my Intel Edison that has the basis of what I need the issue is that it's using socket.io buttons on the html front end to control GIPO pins on the board but it does not read the current state of the GPIO pin when loading the page or if the page is loaded on another device they are not synchronized. I was thinking that booleans could be set on the node.js code that would hold the status of a GPIO and the webpage would constantly check the status of it and set the button state accordingly? I tried some stuff my self but as a beginner I was out of luck. The code in question is on gethub https://github.com/drejkim/LediMote

slava
  • 1,901
  • 6
  • 28
  • 32

1 Answers1

0

Given the socket.io-based app structure you already have, it looks like you should just read the initial GPIO state and send it to the web page with a socket.io message as soon as you get the connection event for the incoming socket.io connection in /lib/routes/socket.js.

Just create a message name and send that message with the initial state upon connection. Then in the client, you just listen for that message and update the state in the web page with whatever is sent as the current state. You can use that same message to update any connected clients any time the state is changed by some other client.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • Could you show me an example for one of the buttons? I'm very new to this still – Neil Mueller Oct 18 '15 at 19:28
  • @NeilMueller - I don't understand exactly what you are asking. The usual process here on Stack Overflow is you do some research, write some code, get stuck somewhere on that code, past a question showing the code you have so far and describing exactly what you are trying to accomplish, and very specifically what problem you had with your code. We don't generally just write code from scratch for you. – jfriend00 Oct 18 '15 at 19:33