A better Python script for uploading images

[RPi-Cam-Web-Interface]

Install the [poster] module by running the command-line:

sudo pip install poster

UploadImage.py (RPI)

#!/usr/bin/env python

import urllib, urllib2, os, os.path, sys
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
from time import sleep

register_openers()

query = { 'id' : 1 }
url = "http://domain.com/path/save_image.php?"+urllib.urlencode(query)

filename = '/dev/shm/mjpeg/cam.jpg'
#print 'Saved: '+filename;

while True:
  try:
    if (os.path.isfile(filename)) :
      values = {'image':open(filename)}
      data, headers = multipart_encode(values)
      headers['User-Agent'] = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
      headers['filename'] = filename
      req = urllib2.Request(url, data, headers)
      req.unverifiable = True
      content = urllib2.urlopen(req).read()
  except:
    print 'Upload failed.';
  sleep(1)

Edit the crontab.

sudo crontab -e

Add the following to the end of the crontab.

0 * * * * /sbin/reboot
@reboot python /home/pi/Documents/GetMacAdx.py &
@reboot python /home/pi/Documents/UploadImage.py &

Reboot the Raspberry PI and the security camera is ready to go!

save_image.php (Server)

<?php

if (!isset($_GET['id'])) {
  echo ('Invalid request!');
  exit(0);
}
$id = intval($_GET['id']);

$image = $_FILES["image"];

if ($image == null) {
   echo ("Missing image!");
   exit(0);
} else {
   echo "Saved image!";
   $filename = "image" . $id . ".jpg";
   $tmp_name = $_FILES["image"]["tmp_name"];
   move_uploaded_file($tmp_name, $filename);
}
?>

[Setup wifi on the command-line]

Turn off the camera LED by adding the following to the end of the file.

/boot/config.txt

disable_camera_led=1

Control your LEDs with your TV remote?! || Arduino IR Tutorial

I created a [XamarinFormsIoT] Windows Core IoT project which can control LEDs and play sounds on a Raspberry PI 3 using C#/XAML. I used a portable dependency interface to expose the GPIO controller which only exists in the UWP project. GPIO is used to control the LEDs. I also ordered an IR receiver so I can detect IR signals from a remote and it works!

Next I need to [find] a UWP library for LIRC.

The [Arduino-IRremote] has a C++ library that can be converted to UWP.

I followed the idea from the video below.

[How to Control the GPIO on a Raspberry Pi with an IR Remote]

Adafruit: [IR (Infrared) Receiver Sensor]

[Raspberry Pis, Remotes & IR Receivers!]

[Xamarin Components]

[Play wav file in Raspberry PI with Windows IoT Core]

[XamarinMediaManager]

[Xamarin Forms: Hello Blinky]

[Windows 10 IoT Core : Setting Startup App]

[UWP on Xbox One]