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.