You are on page 1of 3

หลักการทํางาน

เมือเซนเซอร ์ควันตรวจพบควัน ก็จะส่งสัญญาญไปยังโปรแกรมเพือทีจะประมวลผลและส่งกลับมาเป็ นสัญญาญเสียงสัญญาญไฟกระพริบ


ส่งขอ้ ความและรูปภาพไปยังกลุ่มไลน์ทได
ี ้ตังค่าไว ้

CODE คําสังการทํางาน

/**********************************
* This code for detec the smoke
* if the smoke has detected it will open
* alarm system and sedn notify to LINE application
*********************************/
//get needed library
#include<wiringPi.h>
#include<stdio.h>
//pin specfication
#defineLED0
#defineBUZZER1
#defineSMOKE4
#defineLINE_BUFSIZE1024
voidsiren(void);
intsend_line(void);
// main funcion
intmain(void)
{
intsensordetect = 0; // set default sensor value
//initial device
if(wiringPiSetup() == -1){ //when initialize wiring
failed,printmessageto screen
printf(“setup wiringPi failed !”);
return1;
}
printf(“linker LedPin : GPIO %d(wiringPi pin)\n”,BUZZER); //when
initialize wiring successfully,print message to screen
//setup pin for device
pinMode(LED, OUTPUT);
pinMode(BUZZER, OUTPUT);
pinMode(SMOKE, INPUT);
//run forever
while(1){
sensordetect = digitalRead(SMOKE);//คําสังส่ง line ไปยังโทรศัพท ์
//printf(“sensor status : %d\n”,sensordetect);
printf(“OK!!!\n”);
//echo siren and show bliking led if sensor has detected ( 0 means senser has
detected)
if (sensordetect == 0) {
printf(“hey!!! there are stududent smoking!!!\n”);ขอ้ ความ
siren();
send_line();
}
}
return0;
}
//make a siren sound and blinking led //คําสังส่งเสียง
voidsiren(void) {
int i;
//generate siren low sound
digitalWrite(LED,HIGH);
for (i = 0; i <80; i++) // Wen a frequency sound
{
digitalWrite (BUZZER, HIGH) ;// send voice//ส่งเสียง
delay (1) ;// Delay 1ms
digitalWrite (BUZZER, LOW) ;// do not send voice
delay (1) ;// delay ms
}
digitalWrite(LED,LOW);
//generate siren high sound
for (i = 0; i <100; i++) // Wen Qie out another frequency sound
{
digitalWrite (BUZZER, HIGH) ;// send voice
delay (2) ;// delay 2ms
digitalWrite (BUZZER, LOW) ;// do not send voice
delay (2) ;// delay 2ms
}
}
#!/bin/bash
raspistill –o /home/pi/smoke/smokr.jpg

Convert smoke.jpg –resize 1280×962 smoke01.jpg //คําสังแสดงรูปภาพ

Curl –x POST –H ‘Authorization: Bearer


ciiGBax0ejh0mVKzIkbPagr7Z5FOMD2Zxtgyx1Hyhef’ –F ‘message=hey!!! There are
student smoking’ –F ‘imageFile=@/home/pi/smoke/smoke01.jpg’
https://notify-api.line.line.me/api/notify

intsend_line(void) {
char line[LINE_BUFSIZE];
intlinenr;
FILE *pipe;
/* Get a pipe where the output from the scripts comes in */
pipe = popen(“./sendline.sh”, “r”);
if (pipe == NULL) { /* check for errors */
//perror(argv[0]); /* report error message */
return1; /* return with exit code indicating error */
}
/* Read script output from the pipe line by line */
linenr = 1;
while (fgets(line, LINE_BUFSIZE, pipe) != NULL) {
printf(“Script output line %d: %s”, linenr, line);
++linenr;
}
/* Once here, out of the loop, th
e script has ended. */
pclose(pipe); /* Close the pipe */
return0; /* return with exit code indicating success. */
}
ผลของการทดสอบ

You might also like