Gobetwino Help Needed!

I am designing a simple project that will log every time my door is open, then open webcam software and take a snapshot of the person walking through the door.

For some reason, the only part I am able to get working is getting the webcam software to open up. I know I'm doing something wrong in the code because I'm getting errors beyond belief in Gobetwino. I'm still fairly new to programming, I've only been working with it for a couple months so bear with me for being a little noobish.

Here is my code, can anyone offer some guidance/ suggestions on how to maybe improve it.

For reference I set the hotkey in my webcam program to "home" for it to take a snapshot.

int serInLen = 25;
char serInString[25];


int select;
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     

  Serial.begin(9600);

}


void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, LOW);  
         Serial.println ("DOOR CLOSED");
    
  } 
  else {
    // turn LED off:
  digitalWrite(ledPin,HIGH);
  
   Serial.println("#S|TIMELOG|[]#");
   readSerialString(serInString,1000);
 
 Serial.println("#S|WEBCAM|[]#");        // start Webcam software
  readSerialString(serInString, 5000);  // wait  5  seconds (max) for answer from Gobetwino (=porcess ID)
  
  Serial.println("#S|SENDK|[0&{HOME}]#");
 readSerialString(serInString, 5000);  // wait  5  seconds (max) for answer from Gobetwino (=porcess ID)
  
   
 
  
  }
 



    


}



    


void readSerialString (char *strArray,long timeOut) 
{
   long startTime=millis();
   int i;

   while (!Serial.available()) {
      if (millis()-startTime >= timeOut) {
         return;
      }
   }
   while (Serial.available() && i < serInLen) {
      strArray[i] = Serial.read();
      i++;
   }
}

I'm interested in the readSerialString() function. You pass it a global char array, which you treat as a local variable. Yet, the size of that array is a global variable. Interesting choice of programming styles.

PaulS:
I'm interested in the readSerialString() function. You pass it a global char array, which you treat as a local variable. Yet, the size of that array is a global variable. Interesting choice of programming styles.

That portion of the code was directly stolen from the sample code that came with Gobetwino. I had a simple delay in place and after some troubles, I just copied and pasted a chunk of code from the samples.

EDIT: I actually removed that portion of code as I am realizing it's rather insignificant. I went back and just put delays.

int select;
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     

  Serial.begin(9600);

}


void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, LOW);  
         Serial.println ("DOOR CLOSED");
    
  } 
  else {
    // turn LED off:
  digitalWrite(ledPin,HIGH);
  
   Serial.print("#S|TIMELOG|[");
   Serial.println("]#");
   delay (1000);
 
 Serial.println("#S|WEBCAM|[]#");        // start Webcam software
  delay (5000);  // wait  5  seconds (max) for answer from Gobetwino (=porcess ID)
  
  Serial.println("#S|SENDK|[0&{HOME}]#");
 delay(5000);  // wait  5  seconds (max) for answer from Gobetwino (=porcess ID)
  
  }

}

You don't seem to be looking for changes in the switch input, so it will continually take pictures as long as the switch input remains low.

You've included your sketch, but your question seems to be about how to get Gobetwino to do what you want. In that case you need to know whether the sketch is producing the output you expect (you can check by displaying the output in serial monitor), whether Gobetwino is executing the command you intended (turn on logging in Gobetwino) and whether that command is having the effect you intended.

PeterH:
You don't seem to be looking for changes in the switch input, so it will continually take pictures as long as the switch input remains low.

You've included your sketch, but your question seems to be about how to get Gobetwino to do what you want. In that case you need to know whether the sketch is producing the output you expect (you can check by displaying the output in serial monitor), whether Gobetwino is executing the command you intended (turn on logging in Gobetwino) and whether that command is having the effect you intended.

Well I fairly late last night and worked on a chunk of it this morning. I was able to get all the errors out of Gobetwino. I set 1 command incorrectly but everything else is working in Gobetwino just as I need it to.

The problem is now with the SENDK command. For some reason it is not sending the hotkey to my webcam software. I noticed that if I left the program open Gobetwino would change the Process ID of the program so I had to add a line which would exit the program.

Now the problem exists within the program not registering the hotkey to take the snapshot. I'm not sure if it's the software or not. I can't find another piece of software which also lets me use hotkeys. Or maybe it's something in my code. I know the alt + f4 command is working so they are definitely being sent to the right program, it's just not taking the freaking snapshot!

Can anyone offer some suggestions.

Also I was looking in Gobetwino and the whole code with delays is preforming exactly how I need it to. The problem now only exists within the webcam software or the SENDK command.

**EDIT:**Maybe I need it to hold down the key for a few ms? Is there a way of doing that?

char buffer[5];

int select;
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     

  Serial.begin(9600);

}


void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, LOW);  
       
    
  } 
  else {
    // turn LED off:
  digitalWrite(ledPin,HIGH);
  
Serial.print("#S|LOGTEST|[");
Serial.print(itoa((0), buffer, 10));
Serial.println("]#");
 
 Serial.println("#S|WEBCAM|[]#");        // start Webcam software
  delay (5000);  // wait  5  seconds (max) for answer from Gobetwino (=porcess ID)
  
  Serial.println("#S|SENDK|[0&{HOME}]#");
  delay(5000);
   
   Serial.println("#S|SENDK|[0&%{F4}]#");
  delay(1000);
   
  }
  

}

I'm on my way out the door for a wedding.

Please post the errormessages from GoBetwino, then i will have a look at it later or to morrow.

One thing :

Its not a good idea to mix stuff like this:

Serial.println ("DOOR CLOSED");

With GoBetwino commands.

It will confuse GoBetwino possibly to the extend of not working probably.

How are you dealing with the application launch? Do you assume it's already running and just look up the PID, or assume it's not running and start a new instance and then kill it when you're finished, or what?

Have you discovered a key sequence which reliably causes the application to do what you want? Preferably using plain old keyboard input (mouseless input mode is your friend here) rather than using Windows hotkeys.

Have you confirmed that Gobetwino is sending the keyboard sequence you want to the right process when you want it? It might help to prototype that part using a different application that makes it more obvious what keystrokes it has received - I use Notepad a lot for that.

Serial.println("#S|WEBCAM|[]#");        // start Webcam software
  delay (5000);  // wait  5  seconds (max) for answer from Gobetwino (=porcess ID)
  
  Serial.println("#S|SENDK|[0&{HOME}]#");
  delay(5000);
   
   Serial.println("#S|SENDK|[0&%{F4}]#");
  delay(1000);

In this code you are asuming that GoBetwino send 0 back as the process id, instead of actually reading the processid GoBetwino is sending. Please check the supplied sample code to see how to do that correct. If you are not starting other programs and only start the webcam software once the process id is probebly 0 but assumption is the mother of all fu.. ups.

Also in this code where you read the buttonstate:

  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, LOW);

You probably need some debouncing unless you are doing that in hardware

One more thing that comes to mind:

Does your webcam softwarre open multiple windows ? i know from other people that it can be a problem with he SENDK command. Everytime GoBetwino executes a SENDK command it forces the recieving application's window to be the foreground window, this does not work well if the application opens more than one window.