2 Replies Latest reply on Dec 4, 2014 4:02 PM by KurtE

    Arduino sketch - To create command window?

    KurtE

      This is probably a hair-brain idea,  but I wonder if anyone has created an Arduino sketch for the Edison, that  makes the Arduino serial monitor work more or less like a terminal window to the internal edison (sort of like a putty window).  I know there are some threads that show things like how to get an arduino sketch to to talk to a Node, which also point off to some interesting web pages, like:

      How can I get an Arduino sketch and Node.js script to communicate with each other?

       

      It would not be hard to do this in a very limited way, by having the Arduino sketch read from the Serial object and when it gets a command line, spawn the command with the system command, maybe appending onto the command piping the output to a file, and then after some time have the program open the file and read the contents and write it back out to the Serial object.  This may work for some stuff, but not for interactive things, like suppose I want to type: configure_edison --setup

       

      What would be better, is for the sketch to spawn a child process, whose Serial IO (serin, serout, sererr) to probably pipes that communicate with the Arduino sketch.

       

      Why am I thinking about this?  My Edison on the mini breakout board is semi-toast and at currently the Serial terminal does not output anything. But I can flashall it, it does boot up and bring up the edison window, but I can not talk to it with the hardware serial port to do things like configure things like wifi... But maybe I can still run a sketch...

       

      May not be worth it as I suspect it will completely die soon, as it is running hot (~116) and other stuff was acting flaky, So I have ordered a replacement from Amazon which will probably be here Monday.  But this still may be interesting for other purposes as well.

       

      Does this make sense?

        • 1. Re: Arduino sketch - To create command window?
          CMata_Intel

          Hi KurtE;

           

          Have you tried to access to the terminal console for telnet or SSH? I know there is a way to use the client USB instead of the serial streaming one in order to access the console. I tried it before and is extremely slow. Take a look of this thread. Are you searching for something like this?

           

          Regards

          CMata

          • 2. Re: Arduino sketch - To create command window?
            KurtE

            Not sure, if you need to set something up on the linux, than there may be some issues, but could work.

            For the fun of it, I started a simple sketch to see how bad it would be to have simple sketch to be able to at first do simple commands, which take no input from the user.  instead of using the system command I instead use the popen command, which creates a pipe from the output of the command, which I can then direct to the Serial object.  Current program:

            char abBuf[256];
            void setup() {
              delay(5000);
              Serial.begin(115200);
              delay(2000);
              Serial.println("Serial Terminal");
              Serial.flush();
            }
            
            void loop() {
              // put your main code here, to run repeatedly:
              // readbytesUntil eats CPU so:
              int cbRead = 0;
              for (;;) {
                while (!Serial.available())
                  delay(10);  // give some time for inputs
                abBuf[cbRead] = Serial.read();
                if (abBuf[cbRead] == 13)
                  break;
                if (abBuf[cbRead] > 13)  // ignore control characters...
                  cbRead++;
              }
              abBuf[cbRead] = 0;
            
              Serial.print("cb Read: ");
              Serial.println(cbRead, DEC);
              Serial.print("Cmd: ");
              Serial.println(abBuf);
            
              FILE *fpipe;
              if ( !(fpipe = (FILE*)popen(abBuf,"r")) ) {
                Serial.println("Problems with pipe");
                return;
              }
            
              while ( fgets( abBuf, sizeof(abBuf), fpipe)) {
                Serial.print(abBuf);
              }
              pclose(fpipe);
            }
            

            So far this works for simple things, like: I did an ls of the /tmp directory and cat of the error file.  Part of the output:

            Serial Terminal

            cb Read: 7

            Cmd: ls /tmp

            log.txt

            log_er.txt

            systemd-private-29aac466f3ec41d38837c3720cc04e50-systemd-timesyncd.service-EtZd2A

            watchdog-sample.tmp

            wpa_ctrl_233-1

            cb Read: 19

            Cmd: cat /tmp/log_er.txt

            sysfs-error: err set drive fs_path=/sys/class/gpio/gpio12/drive

             

            sysfs-error: err set drive fs_path=/sys/class/gpio/gpio13/drive

             

            sysfs-error: err set drive fs_path=/sys/class/gpio/gpio14/drive

             

            sysfs-error: err set drive fs_path=/sys/class/gpio/gpio40/drive

             

            sysfs-error: err set drive fs_path=/sys/class/gpio/gpio41/drive

             

            sysfs-error: err set drive fs_path=/sys/class/gpio/gpio42/drive

             

            sysfs-error: err set drive fs_path=/sys/class/gpio/gpio43/drive

             

            sysfs-error: err set drive fs_path=/sys/class/gpio/gpio44/drive

             

            sysfs-error: err set drive fs_path=/sys/class/gpio/gpio45/drive

             

            sysfs-error: err set drive fs_path=/sys/class/gpio/gpio46/drive

             

            Next phase if I continue would be to try to create pipes for both input and output.  I believe the way this is done, is you do a fork call to crate a duplicate child process, where you then create the pipes attached to the first 3 file descriptors, and then do an exec of  /bin/sh

            ...

             

            Again may be fun!