I just got a Arduino on Saturday, and boy, oh boy does it look like fun!! I also got a LCD display.
What I want to do with it as my first project is to make an external web hit counter.
I made a counter on my site in PHP that saves the number of views in a text file. And I've got my computer to send the Arduino a file ever second using MTTTY. The only problem with MTTTY is that I can't edit the file when it's transferring. Also I don't know how to download the file from my server automatically. What program would I use to do this?
I've been Googling like crazy and can't find anything!
Has anybody ever done this before?
Sorry if I sound dumb, but this is my only second day with it.
you should pase the numbers on your computer first, and then send a header with the number to the Arduino:
e.g.
T2696 ( total visitors 2696)
H4777 ( hits: 4777)
If I had to do this in a hurry I would just write a max patch to open the file with the stats, parse the info and send it out over the serial port formatted. PD would also do it OK. You could hack Arudino2Max to send this data, look for the "R" in the MAX patch that gets sent as a request, and append the data. Then in the Arduino, look for the loop identifying the "R" and change the part that follows to read the data received over the port, and then display it on the LCD. Clunky but it will work. The programmer types in here will have better ideas.
There are really only one way for Arduino to communicate with your PC / server. That is by sending and recieving data over the serial line. To get the hit counter to Arduino you can either have some program on the PC / server send the data to Arduino, or you can have a program on the PC / server listening for a request from Arduino. But Arduino knwos nothing about such things as files or protocols or whatever. So you have to come up with a sort of simple protocol, a set of rules that the PC / server and Arduino agrees on.
If you can't program the PC your self, then the best solution will probably be to use something like MTTY to send the data to Arduino, and have the sketch on the Arduino do regular checks for the arrival of data over the serial line. Maybe first use soem kind of utility program to parse the file and extract just the numbr you need.
If you can program the PC yourself, then you can write a small program that will read the file with the hitcounter, parse it into a simple format, like the one suggested in Daniels post, and send it to Arduino, or let it wait for Arduino to ask for it.
A more advanced program, could monitor the hitcounter file and wait for changes and then kick in and do it's job.
If your PC is running Windows you could use a small VB script to regularly download the file from your server to your PC first. I bet that there are also LINUX utilities that can do that, but i don't know anything about that. Or maybe a scheduled FTP program could do that. A VB script would probably also be able to read the contents of the file and write out to a new file only the number you need to send to the Arduino.
Wow! Thanks for all the info! You guys are the best!
I'm really really close! I got cURL to grab the data of count.txt. However, I have to do it manually, so I've got to figure out how to check every second or so. Any ideas on how to do that?
And then, I need to find a serial terminal in Linux (Ubuntu) that can send a file repeatedly like MTTTY.
I would use MTTTY in Windows, but I can't get cURL to work.
Once I can do those two things, I'm good to go! When (if) I get it working, I'll post some pix!
I'm on my way out of the door to the airport to fly to the Piksel festival in Norway. Some cool Arduino folks will be there too
I believe that i actually have a Vb script that can do the downloading somewhere, it just has to be modified a little. But not every second. it was made for fetching an XML file, and was run by the task scheduler in windows every 5 minutes or so. That should solve the download from server to PC part of the equation. But it is on my PC at work which i wont be anywhere near before tuesday.
If you still want / need it when i come back i'll try to dig it out of the dust.
And now of to Norway to make some serious noise at tomorrows concert
You're right, I AM going to get this to work! No matter what!! ;D
I'm really really REALLY! close!!!
I made a shell program that runs the cURL script 5000 times.(Soon to be for as long as the program is running, I just have to figure out the repeat command.)
So, all I have to do is send the file automatically to the arduino.
And I had that working in Windows! But I can't get cURL to work in Windows.
If you don't mind taking a quick look for that script when you get a chance, that would be GREAT!!!!
I'm sure that's a lot nicer then mine!!!!
Because you send the contents of the file many times ?
I don't know anything about the CAt and CURL stuff, but if you could put "Web hits:" in the file before sending it to the display, and then clear the dsplay each time just before sending data to it, it might solve your problem.