本帖最后由 MDebug 于 2017-5-9 16:37 编辑
该装置主要由LPC54114开发版、3.2 寸 TFT 触摸显示屏、esp8266 模块、 NRF24l01 无线数据传输模块、 MLX90614 红外线人体测温、摄像头等传感器组成。
实现的功能:
1) 当我们不在婴儿身边但想要了解婴儿情况时,可以微信发指令给单片机,摄像头会根据单片机处理过后的指令数据执行相应动作对婴儿拍照并发送回父母手机微信 APP, 这样我们就可以看到婴儿的实际情况。 2) 当婴儿的体温不正常或者周围环境异常时, APP 会提醒父母及时注意婴儿的情况。 3)婴儿睡姿检测,家长可以通过对睡姿检测模块上的对应的 led 亮灭判断婴儿睡姿是否正确。
睡姿显示电路
NRF24l01无线与ESP8266WIFI模块
7725摄像头
APP采用JAVA语言通过Android Studio编译器编写,APP部分有2个子页面,婴儿的生理参数页面,显示婴儿的体温和体重,环境参数页面,可以显示被窝温度,还有环境的温湿度。
电脑软件通过采用C#语言通过Visual Studio 编译器编写,可以实时显示各个传感器的数据并且显示摄像头拍摄照片的画面。
调试效果欠佳,还需要继续调试。因为项目后期还有用途,因此只能放出一部分代码,请见谅。
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Net;
- using System.IO;
- using System.Threading.Tasks;
- namespace ANOGround
- {
- class uploadPic
- {
- /// <summary>
- /// 上传图片文件
- /// </summary>
- /// <param name="url">提交的地址</param>
- /// <param name="poststr">发送的文本串 比如:user=eking&pass=123456 </param>
- /// <param name="fileformname">文本域的名称 比如:name="file",那么fileformname=file </param>
- /// <param name="filepath">上传的文件路径 比如: c:/12.jpg </param>
- /// <param name="cookie">cookie数据</param>
- /// <param name="refre">头部的跳转地址</param>
- /// <returns></returns>
- public string HttpUploadFile(string url, string poststr, string fileformname, string filepath, string cookie, string refre)
- {
- // 这个可以是改变的,也可以是下面这个固定的字符串
- string boundary = "------WebKitFormBoundarybrwwfMBZPAaKJAtk";
- // 创建request对象
- HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create("http://fuhome.net/api/photo/");
- webrequest.ContentType = "multipart/form-data; boundary=----WebKitFormBoundarybrwwfMBZPAaKJAtk";
- webrequest.Method = "POST";
- webrequest.Accept = "text/html";
- webrequest.Referer = "http://fuhome.net/api/photo/";
- webrequest.UserAgent = "Mozilla/5.0 (Windows NT 5.2; rv:11.0) Gecko/20100101 Firefox/11.0";
- webrequest.KeepAlive = true;
- // 构造发送数据
- StringBuilder sb = new StringBuilder();
- // 文本域的数据
- sb.Append(boundary);
- sb.Append("\r\n");
- sb.Append("Content-Disposition: form-data; name="sbid"");
- sb.Append("\r\n\r\n");
- sb.Append("1287371275");
- sb.Append("\r\n");
- sb.Append(boundary);
- sb.Append("\r\n");
- sb.Append("Content-Disposition: form-data; name="sbmm"");
- sb.Append("\r\n\r\n");
- sb.Append("0c6d4c1311355b69");
- sb.Append("\r\n");
- sb.Append(boundary);
- sb.Append("\r\n");
- sb.Append("Content-Disposition: form-data; name="feelid"");
- sb.Append("\r\n\r\n");
- sb.Append("321");
- sb.Append("\r\n");
- // 文件域的数据
- sb.Append(boundary);
- sb.Append("\r\n");
- sb.Append("Content-Disposition: form-data; name="uploadfile"; filename="temp.jpg"");
- sb.Append("\r\n");
- sb.Append("Content-Type: ");
- sb.Append("image/jpeg");
- sb.Append("\r\n\r\n");
- string postHeader = sb.ToString();
- byte[] postHeaderBytes = Encoding.UTF8.GetBytes(postHeader);
- //构造尾部数据
- byte[] boundaryBytes = Encoding.ASCII.GetBytes("\r\n" + boundary + "\r\n");
- FileStream fileStream = new FileStream(filepath, FileMode.Open, FileAccess.Read);
- long length = postHeaderBytes.Length + fileStream.Length + boundaryBytes.Length;
- webrequest.ContentLength = length;
- Stream requestStream = webrequest.GetRequestStream();
- // 输入头部数据
- requestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
- // 输入文件流数据
- byte[] buffer = new Byte[checked((uint)Math.Min(4096, (int)fileStream.Length))];
- int bytesRead = 0;
- while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
- requestStream.Write(buffer, 0, bytesRead);
- // 输入尾部数据
- requestStream.Write(boundaryBytes, 0, boundaryBytes.Length);
- WebResponse responce = webrequest.GetResponse();
- Stream s = responce.GetResponseStream();
- StreamReader sr = new StreamReader(s);
- // 返回数据流(源码)
- return sr.ReadToEnd();
- }
- }
- }
复制代码
- #include <string.h>
- #include "gizwits_product.h"
- #include "Hal_key/Hal_key.h"
- #include "Hal_Usart/hal_uart.h"
- #include "Hal_led/Hal_led.h"
- #include "Hal_motor/Hal_motor.h"
- #include "Hal_rgb_led/Hal_rgb_led.h"
- #include "Hal_temp_hum/Hal_temp_hum.h"
- #include "Hal_infrared/Hal_infrared.h"
- #include "Hal_Watchdog/hal_watchdog.h"
- #include "bsp_key.h"
- /**包头*/
- unsigned char datahead[32]={0xFE,0xFD,0xFC,0xFB,0xFA,0xF9,0xF8,0xF7,0xF6,0xF5,0xF4,0xF3,0xF2,0xF1,0xF0,0xEF,0xEE,0xED,0xEC,0xEB,0xEA,0xE9,0xE8,0xE7,0xE6,0xE5,0xE4,0xE3,0xE2,0xE1,0xE0,0xDF};
- u8 gesture=0;
-
- extern unsigned char feeder_rec;//暖奶器开关
- extern unsigned char eat_alert_rec;//喝奶闹钟开关
- extern unsigned char humidifier_rec;//加湿器开关
- extern unsigned char anion_rec;//负离子净化器开关
- extern unsigned char blanket_rec;//恒温床垫开关
- extern unsigned char swing_rec;//摇摆档位选择
- extern unsigned char eat_hour_rec;//定时喝奶时
- extern unsigned char eat_minute_rec;//定时喝奶分
- extern unsigned char pee_rec;//是否尿床
- extern unsigned char eat_status_rec;//上次是否喝奶
- extern unsigned char temperature_rec;//环境温度
- extern unsigned char humidity_rec;//环境湿度
- extern unsigned char baby_heat_rec;//婴儿体温
- extern unsigned char baby_weight_rec;//婴儿体重
- extern unsigned char co_value_rec;//CO浓度
- extern unsigned char bed_heat_rec;//床垫温度
- volatile gizwitsReport_t reportData;//dev_status包含在里面
- keyTypedef_t singleKey[2];
- keysTypedef_t keys;
- void userInit(void)
- {
- Key_GPIO_Config();
- delayInit(72);
- uartxInit();
- rgbLedInit();
- ledGpioInit();
- rgbKeyGpioInit();
- motorInit();
- dht11Init();
- irInit();
- watchdogInit(2); //5,625看门狗复位时间2s
- memset((uint8_t*)&reportData, 0, sizeof(gizwitsReport_t));
- motorStatus(MOTOR_SPEED_DEFAULT);
- }
- void userHandle(void)
- {
- /**控制类数据点*/
- uint8_t curFeeder = 0;
- uint8_t curEat_Alert = 0;
- uint8_t curHumidifier = 0;
- uint8_t curAnion = 0;
- uint8_t curBlanket = 0;
- uint8_t curColor = 0;
- uint8_t curHour = 0;
- uint8_t curMin = 0;
- static uint32_t feederLastTimer=0;
- static uint32_t eat_alertLastTimer=0;
- static uint32_t humidifierLastTimer=0;
- static uint32_t anionLastTimer=0;
- static uint32_t blanketLastTimer=0;
- static uint32_t colorLastTimer=0;
- static uint32_t hourLastTimer=0;
- static uint32_t minLastTimer=0;
-
- /**传感器类数据点*/
- int8_t curTem = 0; //当前的温度
- int8_t curHum = 0; //当前的湿度
- uint8_t curInfrared = 0; //当前红外状态
- uint8_t curPee = 0; //当前是否尿床
- uint8_t curEat = 0; //当前的喝奶状态
- uint8_t curBaby_Heat = 0; //当前婴儿的体温
- uint8_t curBaby_Weight = 0; //当前婴儿的体重
- uint8_t curCO_Value = 0; //当前CO的浓度
- uint8_t curBed_Heat = 0; //当前被窝的温度
- static int8_t lastTem = 0; //上一次的温度,只有上次和这次的不一样才上传
- static int8_t lastHum = 0; //上一次的湿度,只有上次和这次的不一样才上传
- static uint32_t peeLastTimer=0; //上一次尿床检测的TimerCount
- static uint32_t eatLastTimer=0; //上一次喝奶状态的TimerCount
- static uint32_t babyhLastTimer=0;//上一次婴儿体温的TimerCount
- static uint32_t weiLastTimer=0; //上一次婴儿体重的TimerCount
- static uint32_t COLastTimer=0; //上一次CO浓度的TimerCount
- static uint32_t bedhLastTimer=0; //上一次被窝温度的TimerCount
- static uint32_t irLastTimer = 0; //上一次红外的TimerCount
- static uint32_t thLastTimer = 0; //上一次Dht11的TimerCount 只有超过2s以上才上传
- /**获取控制类数据*/
- curFeeder=feeder_rec;
- curEat_Alert=eat_alert_rec;
- curHumidifier=humidifier_rec;
- curAnion=anion_rec;
- curBlanket=blanket_rec;
- curColor=swing_rec;
- curHour=eat_hour_rec;
- curMin=gesture;
- /**获取传感器类数据*/
- curInfrared = irHandle();
- curPee=pee_rec;
- curEat=eat_status_rec;
- curBaby_Heat=baby_heat_rec;
- curBaby_Weight=baby_weight_rec;
- curCO_Value=co_value_rec;
- curBed_Heat=bed_heat_rec;
- curTem=temperature_rec;
- curHum=humidity_rec;
-
- /**控制类数据的更新*/
- if(curFeeder != reportData.devStatus.LED_OnOff)//暖奶器
- {
- if((gizwitsGetTimerCount() - feederLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.LED_OnOff = curFeeder;
- feederLastTimer = gizwitsGetTimerCount();
- printf("LED_OnOff %d \r\n", feederLastTimer);
- }
- }
-
- if(curEat_Alert != reportData.devStatus.Eat_Alert)//喝奶闹钟
- {
- if((gizwitsGetTimerCount() - eat_alertLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.Eat_Alert = curEat_Alert;
- eat_alertLastTimer = gizwitsGetTimerCount();
- printf("Eat_Alert %d \r\n", eat_alertLastTimer);
- }
- }
- if(curHumidifier != reportData.devStatus.Humidity_OnOff)//加湿器
- {
- if((gizwitsGetTimerCount() - humidifierLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.Humidity_OnOff = curHumidifier;
- humidifierLastTimer = gizwitsGetTimerCount();
- printf("Humidity_OnOff %d \r\n", humidifierLastTimer);
- }
- }
-
- if(curAnion != reportData.devStatus.Anion_OnOff)//负离子净化器
- {
- if((gizwitsGetTimerCount() - anionLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.Anion_OnOff = curAnion;
- anionLastTimer = gizwitsGetTimerCount();
- printf("Anion_OnOff %d \r\n", anionLastTimer);
- }
- }
-
- if(curBlanket != reportData.devStatus.Blanket_OnOff)//恒温床垫
- {
- if((gizwitsGetTimerCount() - blanketLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.Blanket_OnOff = curBlanket;
- blanketLastTimer = gizwitsGetTimerCount();
- printf("Blanket_OnOff %d \r\n", blanketLastTimer);
- }
- }
- if(curColor != reportData.devStatus.LED_Color)//摇摆档位
- {
- if((gizwitsGetTimerCount() - colorLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.LED_Color = curColor;
- colorLastTimer = gizwitsGetTimerCount();
- printf("LED_Color %d \r\n", colorLastTimer);
- }
- }
-
- if(curHour != reportData.devStatus.LED_R)//喝奶时
- {
- if((gizwitsGetTimerCount() - hourLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.LED_R = curHour;
- hourLastTimer = gizwitsGetTimerCount();
- printf("LED_R %d \r\n", hourLastTimer);
- }
- }
-
- if(curMin != reportData.devStatus.LED_G)//喝奶分
- {
- if((gizwitsGetTimerCount() - minLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.LED_G = curMin;
- minLastTimer = gizwitsGetTimerCount();
- printf("LED_G %d \r\n", minLastTimer);
- }
- }
-
- /**传感器类数据状态更新*/
- if(curInfrared != reportData.devStatus.Infrared)//红外反射
- {
- if((gizwitsGetTimerCount() - irLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.Infrared = curInfrared;
- irLastTimer = gizwitsGetTimerCount();
- printf("Infrared %d \r\n", irLastTimer);
- }
- }
-
- if(curPee != reportData.devStatus.Pee_OnOff)//尿床检测
- {
- if((gizwitsGetTimerCount() - peeLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.Pee_OnOff = curPee;
- peeLastTimer = gizwitsGetTimerCount();
- printf("Pee_OnOff %d \r\n", peeLastTimer);
- }
- }
-
- if(curEat != reportData.devStatus.Eat_Status)//上次是否喝奶
- {
- if((gizwitsGetTimerCount() - eatLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.Eat_Status = curEat;
- eatLastTimer = gizwitsGetTimerCount();
- printf("Eat_Status %d \r\n", eatLastTimer);
- }
- }
-
- if(curBaby_Heat != reportData.devStatus.Baby_Heat)//婴儿体温
- {
- if((gizwitsGetTimerCount() - babyhLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.Baby_Heat = curBaby_Heat;
- babyhLastTimer = gizwitsGetTimerCount();
- printf("Baby_Heat %d \r\n", babyhLastTimer);
- }
- }
-
- if(curBaby_Weight != reportData.devStatus.Baby_Weight)//婴儿体重
- {
- if((gizwitsGetTimerCount() - weiLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.Baby_Weight = curBaby_Weight;
- weiLastTimer = gizwitsGetTimerCount();
- printf("Baby_Weight %d \r\n", weiLastTimer);
- }
- }
- if(curCO_Value != reportData.devStatus.CO_Value)//一氧化碳浓度
- {
- if((gizwitsGetTimerCount() - COLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.CO_Value = curCO_Value;
- COLastTimer = gizwitsGetTimerCount();
- printf("CO_Value %d \r\n", COLastTimer);
- }
- }
-
- if(curBed_Heat != reportData.devStatus.Bed_Heat)//被窝温度
- {
- if((gizwitsGetTimerCount() - bedhLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
- {
- reportData.devStatus.Bed_Heat = curBed_Heat;
- bedhLastTimer = gizwitsGetTimerCount();
- printf("Bed_Heat %d \r\n", bedhLastTimer);
- }
- }
-
- if((gizwitsGetTimerCount()-thLastTimer) > REPORT_TIME_MAX) //timeout = 2S
- {
- if((curTem != lastTem)||(curHum != lastHum))//温湿度
- {
- reportData.devStatus.Temperature = curTem;
- reportData.devStatus.Humidity = curHum;
-
- lastTem = curTem;
- lastHum = curHum;
-
- printf("Temperature&Humidity [%d-%d] %d %d\r\n", gizwitsGetTimerCount(), thLastTimer, curTem, curHum);
- }
- thLastTimer = gizwitsGetTimerCount();
- }
- }
- void key1ShortPress(void)
- {
- printf("KEY1 PRESS\r\n");
- }
- void key1LongPress(void)
- {
- printf("KEY1 PRESS LONG ,Wifi Reset\r\n");
- gizwitsSetDefault();
- }
- void key2ShortPress(void)
- {
- printf("KEY2 PRESS ,Soft AP mode\r\n");
- //Soft AP mode, RGB red
- ledRgbControl(255, 0, 0);
- gizwitsSetMode(SoftAp_Mode);
- }
- void key2LongPress(void)
- {
- //AirLink mode, RGB Green
- printf("KEY2 PRESS LONG ,AirLink mode\r\n");
- ledRgbControl(0, 128, 0);
- gizwitsSetMode(AirLink_Mode);
- }
- void gestureGet(void)
- {
- if(Key_Scan(GPIOA,GPIO_Pin_1)==1)
- gesture|=0x01;
- else
- gesture&=0xfe;
-
- if(Key_Scan(GPIOA,GPIO_Pin_4)==1)
- gesture|=0x02;
- else
- gesture&=0xfd;
-
- if(Key_Scan(GPIOA,GPIO_Pin_5)==1)
- gesture|=0x04;
- else
- gesture&=0xfb;
-
- if(Key_Scan(GPIOA,GPIO_Pin_7)==1)
- gesture|=0x08;
- else
- gesture&=0xf7;
-
- if(Key_Scan(GPIOB,GPIO_Pin_0)==1)
- gesture|=0x10;
- else
- gesture&=0xef;
-
- if(Key_Scan(GPIOB,GPIO_Pin_6)==1)
- gesture|=0x20;
- else
- gesture&=0xdf;
-
- if(Key_Scan(GPIOB,GPIO_Pin_12)==1)
- gesture|=0x40;
- else
- gesture&=0xbf;
-
- if(Key_Scan(GPIOB,GPIO_Pin_13)==1)
- gesture|=0x80;
- else
- gesture&=0x7f;
- }
- int main(void)
- {
- SystemInit();
-
- userInit();
- singleKey[0] = keyInitOne(0,RCC_APB2Periph_GPIOB, GPIOB, GPIO_Pin_10, key1ShortPress, key1LongPress);
- keys.keyNum++;
- singleKey[1] = keyInitOne(1,RCC_APB2Periph_GPIOA, GPIOA, GPIO_Pin_8, key2ShortPress, key2LongPress);
- keys.keyNum++;
- keys.singleKey = (keyTypedef_t *)&singleKey;
- keyParaInit(&keys);
- gizwitsInit();
-
- printf("Gokit Init Success \r\n");
- while(1)
- {
- gestureGet();
-
- watchdogFeed();
-
- userHandle();//获取各个传感器的状态
-
- gizwitsHandle((gizwitsReport_t *)&reportData);
- }
- }
复制代码
|