Arduino Pushing Data to PHP/Python page

Hello,

I connected my Raspberry Pi and Arduino together and I'm able to use buttons and AJAX calls on the client side of the browser. The client turns on a button and the system will give information back or let a led turn on on the Arduino.

The problem is that the Client always takes the action and the Arduino is the slave device, now I want to change this. For example if I add a button and press it on my Arduino I can send the information via a serial communication line over to the RaspberryPi. But this wont trigger my PHP page. I know I can active listen to the serial port using Python but how can I then push the data from Python to the clients browser?

I do know about web sockets but I wonder if I send data over from Python to PHP, the PHP page will trigger and then update my browser window? Don't think that's possible. Another option is server-side events, but that no different from long polling (it seems to me). Another problem, if I keep the device open in Python then my PHP page wont be able to use this.

So has anyone experience with this or know how to possibly solve this (with another technology) or something else :slight_smile: I really could use some information how to tackle this problem.

dan_fritz:
I know I can active listen to the serial port using Python but how can I then push the data from Python to the clients browser?

You do it by designing your web app so that the browser cooperates with the server to receive updates from the server. This isn't an Arduino question, it's a web app design question, but you have already mentioned AJAX so you already know of one potential solution. There are plenty of other frameworks that support this and you need to pick one (or invent your own, if you don't like using other people's wheels).