more G-Labs products

Author Topic: E-Mail with pics from IP Camera  (Read 2315 times)

April 23, 2016, 07:48:21 AM
Read 2315 times

jshan

  • ***
  • Information
  • Full Member
  • Posts: 71
I've been meaning to write some code so that the basic alarm would send me some pictures from my cameras.  So I'm attaching the app I wrote (C#) which works for me.  In the Basic Alarm app, I populated the "Program to run when triggered" with the program number for the attached app, which, in my case, happened to be 1000.  So now when the alarm is triggered, I now get an e-mail with 3 pictures from each camera, spaced 1 second apart.  I also set up the app so that you can add a button widget into a group and by pressing the button, a test e-mail with the pictures will be sent - that way you don't have to keep setting off your alarm to test if you've set it up correctly.  Hopefully this will help others.

April 25, 2016, 03:47:24 PM
Reply #1

cmptrblder

  • *
  • Information
  • Newbie
  • Posts: 12
Thank you, great work, very useful.  I was wondering, you have two slots for IP cams can this be upped to 10 slots (as homegenie has slots for 10 ip cams?  I don't have that many cams (yet) I've been repurposing old android smart phones for IP cams (have battery backups in them).

April 25, 2016, 06:17:54 PM
Reply #2

jshan

  • ***
  • Information
  • Full Member
  • Posts: 71
Yes, it can be extended very easily.  I put this together pretty quickly so it's not elegant, just brute force. 

To add a 3rd camera:
 - Configure/Programs.  Click on the Contrib/E-Mail Pictures.  Edit.
 - in the Startup Code, add:
      Program.AddInputField("IPCamera.ImageURLThree", "", "Camera 3 image API URL (see your camera docs)");
 - in the Program Code, add:
      var cameraThreeImageURL = Program.InputField("IPCamera.ImageURLThree").Value;   
  - and, just before "Pause(1)", add:
      if (cameraThreeImageURL != "") {
       img = Net.WebService(cameraThreeImageURL)
          .GetBytes();
      Net.AddAttachment( "thrid"+x+".jpg", img );
      }
 - compile.  As long as it says "Saved succeeded" you're good.


May 07, 2016, 02:36:14 PM
Reply #3

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
Useful app, but doesn't with mine (dlink dcs-930l). Probably due to the username/password, you point that the function don't work for you, and so on my side too.

May 07, 2016, 03:01:03 PM
Reply #4

jshan

  • ***
  • Information
  • Full Member
  • Posts: 71
Nolio, do your cameras work with the generic IP app that uses the username/password?  If so, I could update the app to offer the option to enter a username/password.  Please let me know.

May 07, 2016, 03:24:37 PM
Reply #5

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
Yes my camera work with the generic ip app.
You use as model the generic ip app code ?

May 07, 2016, 06:30:54 PM
Reply #6

jshan

  • ***
  • Information
  • Full Member
  • Posts: 71
Yes, I used the generic ip camera app code, specifically, the code to grab the image:

       img = Net.WebService(cameraOneImageURL)
//          .WithCredentials(cameraOneUsername, cameraOnePassword)
          .GetBytes();

 You'll notice I commented out the .WithCredentials.

I don't know why it didn't work seeing as I use the generic app as well and it works fine.    I notice that Gene used Object and I used byte[]. 

I put this together pretty quickly.  If I get time, I'll try to play more and see what happens.

May 23, 2016, 05:10:39 PM
Reply #7

petediscrete

  • ****
  • Information
  • Sr. Member
  • Posts: 220
jshan just to let you know I've managed to integrate your program successfully into the Basic Alarm program to send me pictures upon an alarm activation.I'm using a camera I constructed around a Raspberry PI and camera module running under MotionEye.Homegenie is really starting to become very useful now.

May 23, 2016, 05:16:30 PM
Reply #8

jshan

  • ***
  • Information
  • Full Member
  • Posts: 71
Petediscrete, thank you for letting me know that it was useful.

May 28, 2016, 12:11:18 AM
Reply #9

petediscrete

  • ****
  • Information
  • Sr. Member
  • Posts: 220
Jshan tried a second camera with identical specs but the program does nothing. As soon as I remove reference to the second camera it sends the email pictures ok. Individually the cameras work fine but not together. Any idea what the problem might be. I'm using a seperate GenericIp module for both of them.

May 28, 2016, 04:07:57 PM
Reply #10

jshan

  • ***
  • Information
  • Full Member
  • Posts: 71
Petediscrete, I suspect your second camera is not returning the data that the app is looking for.  To test this, try running only 1 camera but take out your 1st one that's working in the app and replace it with the second one that is not working in the app.  If it does not work, then it's something to do with your camera or setup - carefully examine the setup info that you provided to the app.  Good luck.

May 28, 2016, 04:55:47 PM
Reply #11

petediscrete

  • ****
  • Information
  • Sr. Member
  • Posts: 220
Jshan further update. Was working on 5.21. Downgraded to 5.19 and this has solved the problem. If you want to test your program in 5.21, upgrade and try recompiling it. I was getting strange compiling errors.

Your program is very useful. I'm not a programmer but I reckon if you cleaned it up and expanded it a little it could be an extremely useful program in HG. Maybe if you allowed for the full 10 IP generic modules in the interface it could make for a very professional surveillance utility.

Once again a big thanks for your efforts.

May 28, 2016, 05:21:08 PM
Reply #12

jshan

  • ***
  • Information
  • Full Member
  • Posts: 71
Petediscrete, thanks for the update.  519 is very stable for me and I've been fighting stability issues for several months so I probably won't update until I feel I have to (new HG feature that I need).  I appreciate your comments and you are absolutely correct that this app could do with a makeover.  HG's scripting ability is very powerful but I've found that sometimes I have to fight with it to get it do what I want/expect as was the case with this app.  My first try at this was an elegant solution that didn't work for no apparent reason, so I had to resort to the current alternate method which isn't pretty.  When I get time I'll work on it again but unfortunately this probably won't happen anytime soon.  In the meantime, if you want to add more cameras, look earlier in this thread where I describe an easy way to do it.