Have such an idea, the home put a camera for security purposes or monitoring children, pets, etc.,
The remote phone can control the camera by sending instructions to the camera.
First of all, this idea already has the mature product, but such product has the flaw:
1. Can't DIY some features, out of the bug can only wait for the manufacturer's firmware
2. Due to the use of the service provider's cloud platform, it is possible to generate hundreds of dollars per year.
3. The platform cannot be reused, such as the inability to add NAS features
4. Disclosure of privacy issues
The demand for such products is:
1. Low power because it takes 24 hours to run
2. HD camera, infrared night vision (optional), easy to see the thief's face
3. Stable code
4. History View function
5. Lower Latency
6. Automatically determine if an object is in motion (image processing) in the field of view
7. Best use of free cloud services
Based on the above requirements, the following ideas have been generated:
1. Use the Raspberry Pi or the router that hosts the openwrt as the main body, and you can do the NAS
2. Use a mailbox as a cloud service platform
3. Use a cost-effective camera
Here specifically to analyze:
1. To get through the phone and camera channels, the simplest is the phone and camera directly connected. Independent IP in recent years
Increasingly scarce, we get from the ISP IP many are already intranet IP, that is, cannot directly connect
Phones and cameras.
is a good situation, service area processing NAT inside, the phone has a separate IP, so that can be
The reverse connection way through the mobile phone and the server channel, the phone directly to connect the NAT inside the server is
Cannot succeed because there are a lot of machines in this one IP (unless a DMZ host or virtual server is open)
But the worst case scenario here is that the phone and the server are inside NAT and can't connect to each other.
In this way, external servers are required to relay.
Therefore, I consider the following situations:
1. Using the API
Read the API documentation and know that if you need to use this API, you need to build a
The server is used to interact with the server, although there is free space, but slow is certain,
Because of the delay and stability requirements, plus the cost requirements (if the purchase of virtual space will increase the cost),
The scheme is temporarily pass.
2. Using the Weibo API
On-line search, Weibo opened the micro-blog private messages API, but also see some API users
Spit the micro Bo randomly close the API, so this TBD
3. Using the Fetion API
Because the official does not publish the API, the use of private APIs will create instability,
And it doesn't necessarily support the sending of pictures, so give up temporarily
4. Using the Baidu Cloud API
Baidu Cloud API can store information, although through the method can be used to communicate,
However, special software is needed to support this feature. at present, Baidu Cloud API temporarily used to
Store video material.
5. Use the mailbox
At present, there are countless e-mail service providers in the Internet world, there will be no subsequent inability to use this method,
And the mailbox has been used to communicate since ancient times . Although there are a number of inconvenient factors,
But does not affect the use, the subsequent can do the app solves. This is a temporary use of the mailbox to solve the problem.
Raspberry Pi Test Code
Because Linux is used, it is easy to use Python for the time being. The demo here is
Use the mailbox to receive instructions and send pictures.
#!/usr/bin/python#-*-coding:utf-8-*-#python2.7 mailtest.py fromSmtplibImportSMTP fromSmtplibImportsmtprecipientsrefused fromPoplibImportPOP3 fromTimeImportSleep#For attach img fromEmail.mime.multipartImportMimemultipart fromEmail.mime.textImportMimetext fromEmail.mime.imageImportMimeimageImportSYS smtpserver='smtp.163.com'Pop3server='pop.163.com'email_addr='[email protected]'username='usr'Password='Iwanttofly' #https://docs.python.org/2/library/smtplib.htmldefsend_mail (): Mail_attach='1.jpg'msg=Mimemultipart () msg[" to"] ="'msg[" from"] ="'msg["Subject"] ='my_cmd:1'Msg_text= Mimetext ('','HTML') Msg.attach (msg_text) FP= Open (Mail_attach,'RB') img=Mimeimage (Fp.read ()) Fp.close () Img.add_header ('Content-id', Mail_attach) Msg.attach (img) send_svr=SMTP (smtpserver)#send_svr.set_debuglevel (1) #print Send_svr.ehlo () [0] #服务器属性等Send_svr.login (Username,password)Try: errs=Send_svr.sendmail (email_addr,email_addr,msg.as_string ())exceptsmtprecipientsrefused:Print 'server refused ....'Sys.exit (1) Send_svr.quit ()assertLen (errs) = =0,errsPrint 'Send End'#https://docs.python.org/2/library/poplib.htmldefrecv_mail (): Recv_svr=POP3 (pop3server) recv_svr.user (username) recv_svr.pass_ (password)#msg_cnt is the last Mail index, mail index is range (1, msg_cnt)msg_cnt, mailbox_size =Recv_svr.stat () forIinchRange (1, msg_cnt):Try: #Only list MSG headers to reduce size, use RETR to retrive the whole bodyRsp,msg,siz =recv_svr.top (i, 0)#Print msg forMsg_one_entryinchmsg:ifMsg_one_entry.find ('Subject:') ==0:#response to command here PrintMsg_one_entryexcept: Print '_______error'#Recv_mail ()Send_mail ()
Here are two functions that are used to receive instructions for sending functions that are used to send local images (subsequently converted to camera-generated images)
When the received instruction matches a predefined instruction, the corresponding action (such as three consecutive images, or a MP4) is used.
The starting server address and user name password are to be filled in.
The following shows the effect:
Send it out (imagine that you sent this e-mail on your phone):
Received (imagine you received this email on your phone):
(⊙o⊙) is a picture of a doge
Internet of things-mobile remote Control Home camera (1)