Here is my project
Connect an arduino to a Linux based Network device and run a TOP command
This outputs the same as running TOP on Linux,
So most of the code I know including how to display the output on a LCD but here is what I would like to do
I would like for the Arduino to issue the TOP command through the serial connection and display some of the results on the LCD
I would like to display -load average -Tasks -CPU Stats -Mem Stats -Swap Stats
and possibly some of the top processes
Does anyone know how I would do this or could they give me an example of how to issue a serial command to a device and read back its result to an LCD or a terminal or whatever.
Does anyone know how I would do this or could they give me an example of how to issue a serial command to a device and read back its result to an LCD or a terminal or whatever.
Serial.print("Yo, there! Do this!"); will send a command to a serial device. Presuming that the device responds, Serial.available() and Serial.read() can be used in combination to get the output.
Of course, this presumes that the serial device understands the command. In you case, the serial device is a computer, and computers don't understand squat.
You'll need an application running on the computer, connected to the serial port that the Arduino talks to, that does understand "Yo, there! Do this!" (or whatever...) and can produce a useful response.
Lets say it does understand it.
Would there be a way to parse the serial data before I send it to the LCD ?
What is "it" that would understand the command? If it is an application, wouldn't it make sense to have the more powerful PC application perform the parsing, thus reducing the load on the Arduino AND the amount of serial data sent?
If not, the same function, strtok(), can be used to parse data on the Arduino, once the data has been received and stored. That looks like a lot of data to be sending to the little Arduino, though. No end-of-data marker that I can see.
I guess it would be easier to just explain what the project is.
I have a small home router which I plan to add an Arduino, LCD, Fan, Fan Controller & 4 Temp sensors to
I have the circuit built for the Arduino and everything else, I currently have things like Temp on each sensor, Fan speed in RPM and time going to the LCD but I thought it would be cool to also pull stats from the router itself and send those to the LCD as well. I then noticed a serial connector on the Router so I thought what the heck and hooked up my serial to USB then fired up Putty and logged into the router and noticed the TOP and several other useful commands worked.
So then that got me thinking, what if I could pull the output of those commands directly into the Arduino for further processing and then send the result out to the LCD.
So that is the entire scope of the project, as you see there is no "PC" to do the processing on, its just a router with a serial connection.
Does this information help to paint a clear picture of why I need it to work like I do?
The first thing you need to do is connect with Putty again, and document exactly (A) what you need to input and (B) what the computer outputs.
For example, maybe you have to hit enter 3 times, you get a prompt that says "Login:", you enter a name and press enter, the prompt says "password:", you enter your password and press enter, the prompt says ":>", you type 'top' and press enter, and the screen starts refreshing every second.
Once you have that script, code the Arduino to do the same thing. Use Serial.print's to send your data; use Serial.read() to get data back.
Once you're logged in and have entered the top command, the computer should start sending data every second (I think that's the default). Parse that data for what you want, and send it to the LCD.
As far as parsing the data, the Arduino doesn't support regular expressions so I think the easiest thing to do would be to use something like indexOf().
One thing you'll want to do is only keep the top of the ... top output. A single 80x25 capture will use up all the 2K your Arduino has, so you won't be able to buffer the entire output from the computer.
Ah see this is exactly what I was thinking, I'm very experienced in writing computer programs that automate things so this was the first thing I did, One issue I ran into was that the arduino needed to be setup to read the serial before the router boots otherwise you cant connect.
So to fix this I might just have the Arduino force the router to reboot after it starts up if it doesnt start up faster than the router on its own.
I found that to get what I need you have to
Wait 10 seconds
send username
send enter
wait 2 seconds
send password
send enter
wait 2 seconds
send top
send enter
this should get me where I wanna be, I was thinking to help me debug maybe I would hook a Arduino MEGA up to the router and use 1 serial for the router and the other for a PC so I could redirect the serial output from the router to the PC console and see exactly what the Arduino sees.
I know I could use my UNO as well with the software serial library and bit bang on a couple pins but I have a MEGA that I haven't had to use yet.
I plan to build the arduino in the router so I could use a MEGA if I need more memory, I wouldnt be able to fit a MEGA in there but I could just buy the chip and solder it dead bug onto my board. Im pretty sure they have 2 versions of the chip used in the MEGA, both surface mount but one with legs.
I'm guessing the main thing here is implementing the Terminal Emulation code, so the arduino can react and write to the LCD like it's a VT100 terminal or whatever. Run "man console_codes" under Linux to see the full list of escape codes and their function.
Then just make sure you have getty/mingetty on the Linux box listening on the serial port (if connecting over USB, you'll have to make sure it's listening to the right /dev/ttyUSB* device or whatever), have the arduino log itself in, set the LINES and COLUMNS environment variables properly so ncurses apps know how wide to display, run 'top' and the arduino sketch needs to continually read/parse the inputs, interpreting the ANSI escape codes for boldfacing/clearing display/etc. as needed. Maybe do some searches to see if anybody's already written the terminal emulation code? If not, please share it 'cause I totally want to do this myself someday
edit: Paring down the output to specific fields, though, might be a huge pain in the butt. It looks like top has some command-line options to do it for you though. I highly recommend leaving that to the Linux host and having the Arduino just implement itself as a dumb terminal emulator for the LCD screen (with hooks to auto-login/auto-start the 'top' cmd).
spirilis:
I'm guessing the main thing here is implementing the Terminal Emulation code, so the arduino can react and write to the LCD like it's a VT100 terminal or whatever. Run "man console_codes" under Linux to see the full list of escape codes and their function.
Then just make sure you have getty/mingetty on the Linux box listening on the serial port (if connecting over USB, you'll have to make sure it's listening to the right /dev/ttyUSB* device or whatever), have the arduino log itself in, set the LINES and COLUMNS environment variables properly so ncurses apps know how wide to display, run 'top' and the arduino sketch needs to continually read/parse the inputs, interpreting the ANSI escape codes for boldfacing/clearing display/etc. as needed. Maybe do some searches to see if anybody's already written the terminal emulation code? If not, please share it 'cause I totally want to do this myself someday
edit: Paring down the output to specific fields, though, might be a huge pain in the butt. It looks like top has some command-line options to do it for you though. I highly recommend leaving that to the Linux host and having the Arduino just implement itself as a dumb terminal emulator for the LCD screen (with hooks to auto-login/auto-start the 'top' cmd).
You missed the post where I said its not a Linux machine, Its a router and I cant change the things you suggested.
Here is what my serial LCD keypad panel does beside other awesome things:
It understands all ANSI escape sequences that a character display can do. You can dump info to it via serial and it reports key presses to you via serial. Just one complication: All escape sequences need to end with a '~'.
Here is what my serial LCD keypad panel does beside other awesome things:
It understands all ANSI escape sequences that a character display can do. You can dump info to it via serial and it reports key presses to you via serial. Just one complication: All escape sequences need to end with a '~'.
The only thing preventing you from dumping all info from the router to the panel is that the ansi escape sequences the panel will recognize need to be terminated by a '~', which I can get rid off to make it behave completely like a terminal. If you would like, send me some sample outputs that your router does to a terminal, so I can check them with this panel and give you answers based on test results. Make sure you set the width and height to be 20 and 4 for 20X4 displays. I'm quite interested in what this panel can do in emulating a terminal but I failed to come up with a server that would talk with the panel in ansi language. Your project seems a good fit
liudr:
The only thing preventing you from dumping all info from the router to the panel is that the ansi escape sequences the panel will recognize need to be terminated by a '~', which I can get rid off to make it behave completely like a terminal. If you would like, send me some sample outputs that your router does to a terminal, so I can check them with this panel and give you answers based on test results. Make sure you set the width and height to be 20 and 4 for 20X4 displays. I'm quite interested in what this panel can do in emulating a terminal but I failed to come up with a server that would talk with the panel in ansi language. Your project seems a good fit
I really don't want to fully emulate a terminal and I need to use my LCD because only my modified LCD will fit in the router case properly.
I will try to write some code by this weekend and get some pics of the unit so I can show exactly what I'm doing.
Great! My 20X4 panel is BIG thanks to the size of the display. May not work too well where space is tight. I am never the less interested in what you're doing and may start a project along that line.