Communicate a button click event with sockets
Desire: I have a device or micro-controller i'll call it a mc that I need
to communicate to when a web page button is clicked using sockets.
MC1
<button id ='on1' name='mc1'>On</button>
<button id ='off1' name='mc1'>off</button>
Details: What I am trying to accomplish is when a button is clicked pass
the info to the mc.
What I Tried: Currently I can listens to a port and can write data to the
mc as well as receive data. To do this im starting a file though the
server php cli. The file contains these basic socket functions.
$socket = @socket_create_listen("port#");
$client = socket_accept($socket);
socket_write($client, $msg);
socket_read ($client, 256);
the mc then connect to the server at the port#
Problems: Im having difficulties understanding how to bridge the gap
between my php web page with the button and passing the data that the
button has been clicked to the mc.
Attempt at a Solution: Can i have the file that listens to the port run
and then in a seperate file write to the client?
additional notes: The MC LAN I would like to avoid setting up port
forwarding and the external ip sometimes changes. For these reason I had
choose to have the MC establish the connection to the server thus allowing
the server to write to the MC without needing port forwarding and a non
changing ip address.
Thanks JT
No comments:
Post a Comment