RPi security camera problem [SOLVED]

Hi all, I’m recently building the security camera following the official tutorial on https://github.com/spark/particle-pi-camera without the component “Neopixel ring”.
The shell script and Dropbox API were setup in the same manner and when executing the script a photo can be taken and uploaded to my Dropbox.
However, problem occurred when running the C code with Particle-agent. I only got rid of the parts for Neopixel ring. The errno got a value of 11 and the no photo was taken and uploaded.
My C code is as follow

#include "stdarg.h"
#include "application.h"
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <sys/wait.h>
#include <stdlib.h>

byte PIR_sensor = D8; 
volatile bool pirState = LOW;

void setup()
{
 
   pinMode(PIR_sensor,INPUT_PULLDOWN); //pi GPIO17 
   Serial.begin(9600);


    delay(500);
}


void loop()
{
    //This will run in a loop
    pid_t child_pid;
    int status;
    byte state = digitalRead(PIR_sensor);
    Serial.println(pirState);
  

   if(state == 1){
            Serial.println("Somebody is in this area!"); 
            if(pirState == LOW){
            child_pid = fork();
            if (child_pid == 0) /* fork() returns 0 for the child process */
            {
                Serial.println(errno);
                pirState = HIGH;
                char *const cmd[] = {"",NULL};
                execv("/home/pi/bin/take_photo",cmd); // image capture shell script
                Serial.println("test");
                delay(200);
             }
             else /* parent process */
             {
                 wait(&status); /* wait for child to exit, and store child's exit status */
                 exit(0);  /* parent exits */
             }
        }
   }
    else if(state == 0){
        Serial.println("No one");
        if(pirState == HIGH)
        pirState = LOW;
    }

        delay(1000);
}

 

    #include "stdarg.h"
#include "application.h"
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <sys/wait.h>
#include <stdlib.h>

byte PIR_sensor = D8; 
volatile bool pirState = LOW;

void setup()
{
 
   pinMode(PIR_sensor,INPUT_PULLDOWN); //pi GPIO17 
   Serial.begin(9600);


    delay(500);
}


void loop()
{
    //This will run in a loop
    pid_t child_pid;
   
    byte state = digitalRead(PIR_sensor);
     Serial.println(pirState);
  

   if(state == 1){
            Serial.println("Somebody is in this area!"); 
            if(pirState == LOW){
            child_pid = fork();
            if (child_pid == 0) /* fork() returns 0 for the child process */
            {
                Serial.println(errno);
                pirState = HIGH;
                char *const cmd[] = {"",NULL};
                execv("/home/pi/bin/take_photo",cmd); // image capture shell script
                Serial.println("test");
                delay(200);
             }
             else /* parent process */
             {
                 wait(&status); /* wait for child to exit, and store child's exit status */
                 exit(0);  /* parent exits */
             }
        }
   }
    else if(state == 0){
        Serial.println("No one");
        if(pirState == HIGH)
        pirState = LOW;
    }

        delay(1000);
}

And when executing, the output from serial is

Any ideas toward this situation? Much appreciated for any sharing.

@mohit @jvanier, I saw both of you created/commented on this github project. Could one of you take a look at this please? Thanks!

There is now a simpler way to run processes in the Particle firmware on Raspberry Pi. You can try this code as a starter:

byte PIR_sensor = D8; 
volatile bool pirState = LOW;

void setup()
{
  pinMode(PIR_sensor,INPUT_PULLDOWN); //pi GPIO17 
  Serial.begin(9600);
  delay(500);
}

void loop()
{
  //This will run in a loop
  byte state = digitalRead(PIR_sensor);
  Serial.println(pirState);

  if(state == 1)
  {
    Serial.println("Somebody is in this area!"); 
    if(pirState == LOW)
    {
      pirState = HIGH;
      Process proc = Process::run("/home/pi/bin/take_photo");
      proc.wait();
    }
  }
  else if(state == 0)
  {
    Serial.println("No one");
    if(pirState == HIGH)
      pirState = LOW;
  }

  delay(1000);
}
5 Likes

Thanks a lot!
I have just tried and it now works! :laughing:

1 Like