Syncronizing PHP and arduino

Not sure how to explain this so bear with me.
I have a sketch that "does stuff". During the main loop it checks millis and if millis = 15minutes it spits out a string of characters to serial.
PHP needs to read those characters.

My problem is this is a change in my project.
I was previously using PHP serial class to open the connection to arduino and send start/command/stop bits and then loop in the serial response. This works perfectly because PHP is initiating the chat and opening the connection to arduino.

So to my question. What do you think the best way to now convert this so that I dont have to wrap my whole sketch in a checkserial loop.

I think trying to time this is a bad idea. IE have a cron run in PHP every 15 minutes to open the socket and read hoping that the time will be the same that arduino happens to be spiitting out the serial characters.

I thought also about having the arduino run its serial output over and over and over every few minutes so there would be more chance of catching it with PHP.

The other problem is that arduino resets each time php opens the socket. This will also screw with my loop as it will reset and lose any data it had collected before being able to send it over to php.

meaning my php logging loop will also have to include the checksensors loop.

Sorry for the long post.
Any thoughts or ideas or spit balls would be great.

Any thoughts or ideas or spit balls would be great.

I think that you should start by telling us what operating system you are running PHP on. What is the PHP script doing with the data that it gets?

I think trying to time this is a bad idea. IE have a cron run in PHP every 15 minutes to open the socket and read hoping that the time will be the same that arduino happens to be spiitting out the serial characters.

I agree that trying to read serial data at just the right time is a lousy idea.

I thought also about having the arduino run its serial output over and over and over every few minutes so there would be more chance of catching it with PHP.

Why not have the Arduino not send any data until the PHP script asks for it?

The other problem is that arduino resets each time php opens the socket.

There are ways to permanently and to temporarily modify the Arduino so that this doesn't happen.

ah Paul. i've been MIA for awhile but you are still here helping people. Thanks!!

Duh sorry for my lousy forum ettiquitte (sp?)
I am running PHP on Ubuntu so I can get bidirectional coms via php serial class which doesnt work on winblows.

I do know about the resitor on the reset pin to hold it down and stop the reset. thanks for reminding me. I have it unplugged because Its a pain when constantly uploading new sketches for testing. ( I just dragged this old project out of the closet when I got a brain storm and some free time)

The PHP script simply logs the values it gets to a mysql db. nothing fancy.

For arduino to not send any data until asked is what I want. Unfortunatly I think that will require wrapping the whole sketch in a checkserial loop which im trying to avoid (since everything else works).

Maybe I should rethink that.

Unfortunatly I think that will require wrapping the whole sketch in a checkserial loop which im trying to avoid (since everything else works).

I don't see why that would be necessary. Isn't the sending code in a single function? Or is it all over the place?

its kind of all over the place. One function checks the sensor values. one does the formatting of the data and sending in a kooky string with start and stop bits built in so PHP can parse it.
Maybe I can just wrap the sending data part in a checkserial.
If I just have one function in the checkserial will arduino break out of its loop when it gets a serial command? If the checkserial function isnt called at the same time that PHP sends the serial command arduino wont respond to it. Unless my thinking is off on how that works.

I think we'd need to see your code. In loop(), you'd add a call to Serial.available() and to Serial read(), to see if PHP sent anything that looked like "Feed me!" (or whatever). if so, set a flag indicting that output should actually occur,

Prior to each call to output serial data, see if that flag is set. If not, don't call the Serial.print(), Serial.write(), or Serial.println() functions.

ok that gives me an idea. thanks im going to piddle with this code for awhile and see what I come up with. I'd post up mine but its a mess right now.

I am using millis to send values at certain time intervals. I needed this when I was sending data over serial and actually logging into a router and using php curl via telnet.
Now that the arduino is only checking sensor values and doesnt have to do the leg work. And now that you reminded me about the reset, I think I can just loop the whole thing and spit serial data out each loop because I dont actually need to tell arduino to do anything anymore. Just need to get the data it spits every loop.