基于树莓派的智能家居项目整理

一、功能介绍
二、设计框图
三、实物展示
四、程序

一、功能介绍
硬件:树莓派3B、LD3320语音识别模块、pi 摄像头、继电器组、小灯、火焰传感器、蜂鸣器、电             磁锁

项目框架:
    采用了简单工厂模式的一个设计方式。稳定,拓展性更强,在C语言中,因为没有接口、类这一说法,所以这里采用了结构体来“等效替换”。有四个灯,所以我创建了四个灯控制.c程序。每一个程序文件中,都有一个设备结构体,每个程序文件的函数实现方法不同,当有新设备进入只需要在创建一个.c文件,改变函数实现方法即可。初始化的时候,通过链表将各个模块连接起来(头插法)。在要使用某个模块时,只需要使用链表遍历,找到所需模块去调用功能
具体功能是
1、可通过ld3320语音模块的口令模式,口令+具体控制,通过串口把控制指令传给树莓派,来控  制客厅、餐厅、二楼、浴室的灯,以及 人脸识别功能。
2、也可以通过socket客户端来发指令来控制灯的开关,电磁锁
3、火灾报警,当火焰传感器检测到火焰的时候,蜂鸣器会报警。
4、视频监控采用开源mjpg-Streamer来实现的,程序执行时创建一个视频监控的线程,用system函数调用启动脚本运行,监控画面可在http://172.20.10.8:8080去看到
5、人脸识别开锁,人脸识别功能是使用的翔云平台的人脸识别解决方案,需要安装libcurl 和 openSSl库来支持https协议,通过系统调用wget +http://172.20.10.8:8080/?action=snapshot -O ./huyu1.jpg 指令到树莓派的监控页面"去截取一帧保存到本地,获取图片的base64编码,工程文件夹下也有一张照片,huyu.jpg格式,相当于采集的人脸。也是获取图片的base64编码,通过sprintf函数将访问翔云需要的两张图片的base64编码与Key、secret、typeId、format拼接在一起,通过https协议去访问翔云平台, 识别成功后会将识别结果返回,通过回调函数readData将返回的字符串读到readBuff里,通过strstr去readbuff里找有没有字符’是’,如果识别成功就去控制电磁锁打开。

二、设计框图

  请添加图片描述

 四、程序

   control Device

#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>



struct Devices
{
   char name[128];
   int status;
   int pinName;
   int (*open)(int pinName);
   int (*close)(int pinName);
   int (*deviceInit)(int pinName);

   void (*justDoOnce)();
   char* (*getFace)();
   char* (*getPicFromOCRBase64)(); 
   
   int (*readStaus)(int pinName);
   int (*changeStatus)(int status);

    
   
   struct Devices* next;
};

struct Devices* addbathroomLink(struct Devices* head);
struct Devices* addupstairLink(struct Devices* head);
struct Devices* addrestaurantLink(struct Devices* head);
struct Devices* addlivingroomLink(struct Devices* head);
struct Devices* addcameraToDeviceLink(struct Devices *head);
struct Devices* addfiretoLink(struct Devices* head);
struct Devices* addBeepToDeviceLink(struct Devices *phead)	;

 inoutcommand

#include <stdlib.h>
#include <wiringPi.h>

struct inputcommander{
   char commandName[128]; 
   char deviceName[128];
   char command[32];
   int (*init)(struct inputcommander*voicer ,char* ipAddress,char* port);
   int (*getCommand)(struct inputcommander* voicer);

   char log[1024];
   int fd;

   char port[12];
   char ipAddress[32];
   int sfd;
   struct inputcommander*next;
   	};
   

 struct inputcommander* addvoiceControlInputLink(struct inputcommander* phead);
 struct inputcommander* addsockControlLink(struct inputcommander* phead);

bathroom

#include "controDevice.h"

int bathroomLightopen(int pinName){
     digitalWrite(pinName,LOW);
  }

int bathroomLightclose(int pinName){
     digitalWrite(pinName,HIGH);
	 
  }

int bathroomLightInit(int pinName){
    
	pinMode(pinName,OUTPUT);
	digitalWrite(pinName,HIGH);
}



struct Devices bathroomLight = {
	  .name="bathroomLight",
	  .pinName=22,	
	  .open=bathroomLightopen,
	  .close=bathroomLightclose,
  	  .deviceInit=bathroomLightInit
  	  
};


struct Devices* addbathroomLink(struct Devices* head){
     if(head==NULL){
         return &bathroomLight;
	 }
	 else
	 {
        bathroomLight.next=head;
		head=&bathroomLight;
		return head;
	   }
}

livinglight

#include "controDevice.h"

int livingroomLightopen(int pinName){
     digitalWrite(pinName,LOW);
  }

int livingroomLightclose(int pinName){
     digitalWrite(pinName,HIGH);
	 
  }

int livingroomLightInit(int pinName){
    
	pinMode(pinName,OUTPUT);
	digitalWrite(pinName,HIGH);
  }

int livingroomLightChangestatus(int status){

  }

struct Devices livingroomLight = {
	  .name="livingroomLight",
	  .pinName=24,	
	  .open=livingroomLightopen,
	  .close=livingroomLightclose,
  	  .deviceInit=livingroomLightInit,
  	  .changeStatus=livingroomLightChangestatus
};

struct Devices* addlivingroomLink(struct Devices* head){
     if(head=&#
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

追着太阳跑1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值