Foscam Plugin - control/capture Foscam ip camera

I am just another humble hobbyist building plugins for fun. My plugins largely evolve from a desire to integrate devices in my home that have some form of web interface or api (webcams, a/v receivers, etc). I welcome your feedback, suggestions and challenges :)
User avatar
discgolfer1138
Posts: 45
Joined: Thu Jul 28, 2011 10:56 pm
Location: Golden, CO
Contact:

Foscam Plugin for Indigo

Post by discgolfer1138 »

Hi folks, I'm working on an Indigo plugin to wrap and extend the web api for Foscam webcams. One of the actions I am adding to this plugin is the ability to send an email containing a capture from the camera. I am currently doing all the mail-sending manually using python's smtplib. I'd much prefer to use the provided indigo.server.sendEmailTo method so that I can leverage the built-in smtp settings instead of unnecessarily managing them in plugin preferences. The only pickle is that I don't see anything in the documentation regarding if/how attachments can be added to the email message if it is sent using sendEmailTo. Any help would be greatly appreciated. All my current plugin projects are hosted on GitHub, and I welcome anyone interested to fork them at their leisure :)

https://github.com/discgolfer1138/indigo_foscam
(the plugin mentioned above; wrapper for foscam webcam)

https://github.com/discgolfer1138/indigo_pushover
(wrapper for the Pushover API, allows you to send push notifications to mobile devices)

https://github.com/discgolfer1138/indigo_yamaharx
(wrapper for web api for Yamaha RX-series receivers)
Indigo 6.1.0 | Mac Mini | OS 10.10.3 (Yosemite)
Fork Me on GitHub!
User avatar
jay (support)
Site Admin
Posts: 18379
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: adding attachments mail sent via indigo.server.sendEmail

Post by jay (support) »

We don't currently support attachments, though it is on the feature request list.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
User avatar
discgolfer1138
Posts: 45
Joined: Thu Jul 28, 2011 10:56 pm
Location: Golden, CO
Contact:

Re: adding attachments mail sent via indigo.server.sendEmail

Post by discgolfer1138 »

thanks for your quick response, Jay!

Is there any chance the app-wide email settings are accessible in some way. I figure until attachment support is available, I can still use my existing mail-sending methods but pull the smtp auth info from app config instead of requiring a separate plugin or action config...

here's a quick snippet of how I'm sending mail with attachements via smtplib:

Code: Select all

	def sendViaEmail(self, pluginAction, dev):
		subject = pluginAction.props['subject']
		recipient = pluginAction.props['recipient']

		# Create the container (outer) email message.
		msg = MIMEMultipart()
		msg['Subject'] = subject
		# me == the sender's email address
		# family = the list of all recipients' email addresses
		msg['From'] = sender
		msg['To'] = recipient
		msg.preamble = 'cam snap test'

		# Open the files in binary mode.  Let the MIMEImage class automatically
		# guess the specific image type.
		fp = open('/tmp/snap.jpg', 'rb')
		img = MIMEImage(fp.read())
		fp.close()
		msg.attach(img)

		# Send the email via our own SMTP server.
		sender = 'user@gmail.com'
		smtp_user = 'user@gmail.com'
		smtp_pass = 'passgoeshere'
		smtp_host = 'smtp.gmail.com'
		smtp_port = 587

		s = smtplib.SMTP(smtp_host,smtp_port)
		s.ehlo()
		s.starttls()
		s.ehlo
		s.login(smtp_user, smtp_pass)
		s.sendmail(sender, recipient, msg.as_string())
		s.quit()
Indigo 6.1.0 | Mac Mini | OS 10.10.3 (Yosemite)
Fork Me on GitHub!
User avatar
matt (support)
Site Admin
Posts: 21470
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: adding attachments mail sent via indigo.server.sendEmail

Post by matt (support) »

Unfortunately, there are no APIs for retrieving that account settings. I'm not sure we would want to provide access to the password from an API. You can, of course, add plugin config UI for the SMTP settings.

What about saving the image to a Web server (you could even put it into the images or static folder of Indigo's built-in Web Server, I believe) and then including a link to that in the email? Although Indigo only supports plain text email, so you cannot inline the image in HTML which would be nice.
Image
User avatar
discgolfer1138
Posts: 45
Joined: Thu Jul 28, 2011 10:56 pm
Location: Golden, CO
Contact:

Re: adding attachments mail sent via indigo.server.sendEmail

Post by discgolfer1138 »

I guess I'll have to go the plugin config route for now, no worries :)

the specific reason I'm trying to send an image as an email attachment is to facilitate Actions like:
- Post snapshot to Facebook: FB provides each user with a secret post-via-email address. All i have to do is send an email with an image attached to this address and it'll show up on my Facebook wall
- Send snapshot by MMS: certain carriers (like AT&T) let you send an MMS message to your phone via email like this: 3035551212@mms.att.net.

I have an IoLinc hooked up to my doorbell and an outdoor webcam pointed at the doorstep. With the aforementioned scenarios, I can then send a camera snap to my Facebook wall or as a picture msg to my phone whenever someone rings the doorbell. I have both of these things working now with an embedded python script, but I'd much prefer to roll this functionality into my Foscam plugin so others can enjoy it :)
Indigo 6.1.0 | Mac Mini | OS 10.10.3 (Yosemite)
Fork Me on GitHub!
User avatar
matt (support)
Site Admin
Posts: 21470
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: adding attachments mail sent via indigo.server.sendEmail

Post by matt (support) »

discgolfer1138 wrote:I have an IoLinc hooked up to my doorbell and an outdoor webcam pointed at the doorstep. With the aforementioned scenarios, I can then send a camera snap to my Facebook wall or as a picture msg to my phone whenever someone rings the doorbell
Very cool usage scenario.
Image
User avatar
discgolfer1138
Posts: 45
Joined: Thu Jul 28, 2011 10:56 pm
Location: Golden, CO
Contact:

Re: adding attachments mail sent via indigo.server.sendEmail

Post by discgolfer1138 »

It certainly makes for some interesting photos... My wife threw a surprise b-day party for me on Sunday and insisted that everyone ring the doorbell on the way out. Here's a few of the 'safer' captures:

Image
Image

also good for random photos of food delivery personnel:
Image
Image
Indigo 6.1.0 | Mac Mini | OS 10.10.3 (Yosemite)
Fork Me on GitHub!
colovin
Posts: 175
Joined: Tue Oct 27, 2009 11:55 pm

Re: adding attachments mail sent via indigo.server.sendEmail

Post by colovin »

This looks interesting. How do you install it? Do you drag the "indigo_foscam-master folder", into the "Library:Application Support:Perceptive Automation:Indigo 6:Plugins", folder?
Indigo 7.1.1, OS 10.14.6, MacMini .3.2 GHz 6 Intel Core i7, 64 GB ram
User avatar
discgolfer1138
Posts: 45
Joined: Thu Jul 28, 2011 10:56 pm
Location: Golden, CO
Contact:

Re: adding attachments mail sent via indigo.server.sendEmail

Post by discgolfer1138 »

I found the easiest way is to clone the repo somewhere on your server and then symlink into your plugins folder:

Code: Select all

prompt# cd ~/username/Projects
prompt# git clone git@github.com:discgolfer1138/indigo-foscam.git
prompt# cd /Library/Application\ Support/Perceptive\ Automation/Indigo\ 6/Plugins
prompt# sudo ln -s /Users/username/Projects/indigo-foscam foscam.indigoPlugin
Note: be sure to that the name of the symlink uses the .indigoPlugin extension
**Note: the plugin is alpha (at best), I welcome any suggestions. Feel free to fork my repo and contribute!
Indigo 6.1.0 | Mac Mini | OS 10.10.3 (Yosemite)
Fork Me on GitHub!
User avatar
discgolfer1138
Posts: 45
Joined: Thu Jul 28, 2011 10:56 pm
Location: Golden, CO
Contact:

Re: adding attachments mail sent via indigo.server.sendEmail

Post by discgolfer1138 »

Just released a new build of the foscam plugin with a bunch of new actions

https://github.com/discgolfer1138/indig ... /tag/0.1.1

The following actions are now supported:
Move Camera (up, down, left, right)
Stop Movement
Enable/Disable Streams
Activate/Deactivate Motion Alarm
Enable/Disable IR leds
Email Snapshot
Indigo 6.1.0 | Mac Mini | OS 10.10.3 (Yosemite)
Fork Me on GitHub!
ckeyes888
Posts: 2431
Joined: Thu Nov 26, 2009 2:41 pm
Location: Kalispell, MT

Re: adding attachments mail sent via indigo.server.sendEmail

Post by ckeyes888 »

Just tried a F18904W that wouldn't work. Any chance of adding any more cams any time soon?

Thanks,

Carl
User avatar
discgolfer1138
Posts: 45
Joined: Thu Jul 28, 2011 10:56 pm
Location: Golden, CO
Contact:

Re: adding attachments mail sent via indigo.server.sendEmail

Post by discgolfer1138 »

As long as the cgi endpoints are the same, it should support most of Foscam's mjpeg cams.

But, I have two fi8905e's installed at home and I can't imagine the fi8904w is much different. I'll test against those and get back to you.
Indigo 6.1.0 | Mac Mini | OS 10.10.3 (Yosemite)
Fork Me on GitHub!
User avatar
discgolfer1138
Posts: 45
Joined: Thu Jul 28, 2011 10:56 pm
Location: Golden, CO
Contact:

Re: adding attachments mail sent via indigo.server.sendEmail

Post by discgolfer1138 »

ok, I have rewritten much of the plugin and tested that all the actions work. New release is now available!
https://github.com/discgolfer1138/indig ... /tag/1.0.0

note: Please uninstall any previous versions and remove any actions devices.. The release contains changes that are not backwards compatible (thus the major version)

@ckeyes888, let me know if this works for you! If not, please open an issue with any debugging info you may be able to provide here:
https://github.com/discgolfer1138/indigo-foscam/issues
Indigo 6.1.0 | Mac Mini | OS 10.10.3 (Yosemite)
Fork Me on GitHub!
User avatar
matt (support)
Site Admin
Posts: 21470
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: adding attachments mail sent via indigo.server.sendEmail

Post by matt (support) »

Great -- thanks for sharing.

I just changed the title of the first post on this thread to "Foscam Plugin for Indigo" so it will be easier for folks to find it.
Image
User avatar
discgolfer1138
Posts: 45
Joined: Thu Jul 28, 2011 10:56 pm
Location: Golden, CO
Contact:

Foscam Plugin - control/capture Foscam ip camera

Post by discgolfer1138 »

Installation Instructions:
  1. Download latest release here
Actions Supported:
  • Move Camera (up, down, left, right)
  • Go to or set preset position
  • Stop Movement
  • Enable/Disable Streams
  • Activate/Deactivate Motion Alarm
  • Enable/Disable IR leds
  • Email Snapshot
States Exposed:
  • X Position
  • Y Position
Supported Cameras:
Due to differences in the cgi paths, this plugin does not yet support the 9000-series Foscam HD cameras at this time. (models FI9805E, FI9805W, FI9821W)

Huge thanks to Tim Hamer for his huge contributions to the newly-expanded list of supported actions!

The source code is available for collaboration on GitHub
Bugs can be reported here
Indigo 6.1.0 | Mac Mini | OS 10.10.3 (Yosemite)
Fork Me on GitHub!
Post Reply

Return to “thechad.io”