XMEN BLOGGER: Nikon D7000 - Raspberry Pi as an Access Point to control your camera w/Raspbian

Thursday, January 05, 2017

Nikon D7000 - Raspberry Pi as an Access Point to control your camera w/Raspbian


From:
http://dslrdashboard.info/
http://digicamcontrol.com/doc/



You need:

- Raspberry Pi 2B, because it has 4 USB port, and I need it to control my Nikon camera and my Celestron teelescope (if you need more info, check this) with Raspbian installed.
- USB Wifi dongle compatible.
- External battery (5V output) to do power to your Raspberry Pi.
- USB cable (USB to mini-USB), to connect raspberry pi to Nikon D7000 camera.

First step:

- Install Raspbian (if you have doubts, please check raspbian.org.

- Update your Raspberry Pi from repositories:

pi@raspsrv $ sudo apt-get update
pi@raspsrv $ sudo apt-get upgrade

- And install rpi-update:

pi@raspsrv $ sudo apt-get install rpi-update
pi@raspsrv $ sudo rpi-update

Please, reboot when finish!!

- Troubleshooting... (If needed)

pi@raspsrv $ sudo apt-get install ca-certificates

pi@raspsrv $ sudo apt-get install ntpdate
pi@raspsrv $ sudo ntpdate -u ntp.ubuntu.com

Second step:

Configure your Raspberry Pi as an Acces Point.

1. Install all that you need:

pi@raspsrv $ sudo apt-get install hostapd isc-dhcp-server

# Probably you don't need install this:
pi@raspsrv $ sudo apt-get install iptables-persistent

If you have a non-common WiFi adapter, you can update hostapd driver from adafruit...

pi@raspsrv $ wget http://adafruit-download.s3.amazonaws.com/adafruit_hostapd_14128.zip
pi@raspsrv $ unzip adafruit_hostapd_14128.zip

pi@raspsrv $ sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.ORIG
pi@raspsrv $ sudo mv hostapd /usr/sbin
pi@raspsrv $ sudo chmod 755 /usr/sbin/hostapd

2. Edit your interfaces file to configure wlan0 adapter:

pi@raspsrv $ cat /etc/network/interfaces
auto lo

iface lo inet loopback
iface eth0 inet dhcp
#iface eth0 inet static
# address 192.168.0.190
# netmask 255.255.255.0
# gateway 192.168.0.1

allow-hotplug wlan0
#iface wlan0 inet manual
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet dhcp
iface wlan0 inet static
address 192.168.5.1
netmask 255.255.255.240
gateway 192.168.0.1

pre-up iptables-restore < /etc/iptables.ipv4.nat

3. Edit your DHCP daemon config file:

pi@raspsrv $ cat /etc/dhcp/dhcpd.conf
#
# Sample configuration file for ISC dhcpd for Debian
#
#

# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
ddns-update-style none;

# option definitions common to all supported networks...
##option domain-name "example.org";
##option domain-name-servers ns1.example.org, ns2.example.org;

default-lease-time 600;
max-lease-time 7200;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.

#subnet 10.152.187.0 netmask 255.255.255.0 {
#}

# This is a very basic subnet declaration.

#subnet 10.254.239.0 netmask 255.255.255.224 {
# range 10.254.239.10 10.254.239.20;
# option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
#}

# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.

#subnet 10.254.239.32 netmask 255.255.255.224 {
# range dynamic-bootp 10.254.239.40 10.254.239.60;
# option broadcast-address 10.254.239.31;
# option routers rtr-239-32-1.example.org;
#}

# A slightly different configuration for an internal subnet.
#subnet 10.5.5.0 netmask 255.255.255.224 {
# range 10.5.5.26 10.5.5.30;
# option domain-name-servers ns1.internal.example.org;
# option domain-name "internal.example.org";
# option routers 10.5.5.1;
# option broadcast-address 10.5.5.31;
# default-lease-time 600;
# max-lease-time 7200;
#}

# Hosts which require special configuration options can be listed in
# host statements. If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.

#host passacaglia {
# hardware ethernet 0:0:c0:5d:bd:95;
# filename "vmunix.passacaglia";
# server-name "toccata.fugue.com";
#}

# Fixed IP addresses can also be specified for hosts. These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP. Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.
#host fantasia {
# hardware ethernet 08:00:07:26:c0:a5;
# fixed-address fantasia.fugue.com;
#}

# You can declare a class of clients and then do address allocation
# based on that. The example below shows a case where all clients
# in a certain class get addresses on the 10.17.224/24 subnet, and all
# other clients get addresses on the 10.0.29/24 subnet.

#class "foo" {
# match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
#}

#shared-network 224-29 {
# subnet 10.17.224.0 netmask 255.255.255.0 {
# option routers rtr-224.example.org;
# }
# subnet 10.0.29.0 netmask 255.255.255.0 {
# option routers rtr-29.example.org;
# }
# pool {
# allow members of "foo";
# range 10.17.224.10 10.17.224.250;
# }
# pool {
# deny members of "foo";
# range 10.0.29.10 10.0.29.230;
# }
#}

subnet 192.168.5.0 netmask 255.255.255.240 {
range 192.168.5.5 192.168.5.10;
option broadcast-address 192.168.5.15;
option routers 192.168.5.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name "wifi.local";
option domain-name-servers 8.8.8.8, 8.8.4.4;
}

4. Edit your DHCP server config file:

pi@raspsrv / $ cat /etc/default/isc-dhcp-server
# Defaults for isc-dhcp-server initscript
# sourced by /etc/init.d/isc-dhcp-server
# installed at /etc/default/isc-dhcp-server by the maintainer scripts

#
# This is a POSIX shell fragment
#

# Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf).
#DHCPD_CONF=/etc/dhcp/dhcpd.conf

# Path to dhcpd's PID file (default: /var/run/dhcpd.pid).
#DHCPD_PID=/var/run/dhcpd.pid

# Additional options to start dhcpd with.
# Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead
#OPTIONS=""

# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. "eth0 eth1".
##INTERFACES=""
INTERFACES="wlan0"

5. Edit your host APD config file:

pi@raspsrv / $ cat /etc/hostapd/hostapd.conf
interface=wlan0
driver=nl80211
#driver=rtl871xdrv
ssid=MyPi
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=Raspb3rry
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

6. Edit your host APD daemon config file:

pi@raspsrv / $ cat /etc/default/hostapd
# Defaults for hostapd initscript
#
# See /usr/share/doc/hostapd/README.Debian for information about alternative
# methods of managing hostapd.
#
# Uncomment and set DAEMON_CONF to the absolute path of a hostapd configuration
# file and hostapd will be started during system boot. An example configuration
# file can be found at /usr/share/doc/hostapd/examples/hostapd.conf.gz
#
#DAEMON_CONF=""
DAEMON_CONF="/etc/hostapd/hostapd.conf"

# Additional daemon options to be appended to hostapd command:-
# -d show more debug messages (-dd for even more)
# -K include key data in debug messages
# -t include timestamps in some debug messages
#
# Note that -B (daemon mode) and -P (pidfile) options are automatically
# configured by the init.d script and must not be added to DAEMON_OPTS.
#
#DAEMON_OPTS=""

7. Edit your SYSCTL config file:

pi@raspsrv / $ cat /etc/sysctl.conf
#
# /etc/sysctl.conf - Configuration file for setting system variables
# See /etc/sysctl.d/ for additonal system variables
# See sysctl.conf (5) for information. #

#kernel.domainname = example.com

# Uncomment the following to stop low-level messages on console kernel.printk = 3 4 1 3

###############################################################
# Functions previously found in netbase
#

# Uncomment the next two lines to enable Spoof protection (reverse-path filter)
# Turn on Source Address Verification in all interfaces to
# prevent some spoofing attacks
#net.ipv4.conf.default.rp_filter=1
#net.ipv4.conf.all.rp_filter=1

# Uncomment the next line to enable TCP/IP SYN cookies
# See http://lwn.net/Articles/277146/
# Note: This may impact IPv6 TCP sessions too
#net.ipv4.tcp_syncookies=1

# Uncomment the next line to enable packet forwarding for IPv4
#net.ipv4.ip_forward=1
net.ipv4.ip_forward=1

# Uncomment the next line to enable packet forwarding for IPv6
# Enabling this option disables Stateless Address Autoconfiguration
# based on Router Advertisements for this host
#net.ipv6.conf.all.forwarding=1


###################################################################
# Additional settings - these settings can improve the network
# security of the host and prevent against some network attacks
# including spoofing attacks and man in the middle attacks through
# redirection. Some network environments, however, require that these
# settings are disabled so review and enable them as needed.
#
# Do not accept ICMP redirects (prevent MITM attacks)
#net.ipv4.conf.all.accept_redirects = 0
#net.ipv6.conf.all.accept_redirects = 0
# _or_
# Accept ICMP redirects only for gateways listed in our default
# gateway list (enabled by default)
# net.ipv4.conf.all.secure_redirects = 1
#
# Do not send ICMP redirects (we are not a router)
#net.ipv4.conf.all.send_redirects = 0
#
# Do not accept IP source route packets (we are not a router)
#net.ipv4.conf.all.accept_source_route = 0
#net.ipv6.conf.all.accept_source_route = 0
#
# Log Martian Packets
#net.ipv4.conf.all.log_martians = 1
#

# rpi tweaks
vm.swappiness=1
vm.min_free_kbytes = 8192

8. Add a iptables file:

pi@raspsrv / $ cat /etc/iptables.ipv4.nat
# Generated by iptables-save v1.4.14 on Thu Nov 26 08:15:51 2015
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m comment --comment "Accept all ingoing" -j ACCEPT
-A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i wlan0 -o eth0 -j ACCEPT
-A OUTPUT -m comment --comment "Accept all outgoing" -j ACCEPT
COMMIT
# Completed on Thu Nov 26 08:15:51 2015
# Generated by iptables-save v1.4.14 on Thu Nov 26 08:15:51 2015
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o eth0 -j MASQUERADE
-A POSTROUTING -o eth0 -j MASQUERADE
-A POSTROUTING -o wlan0 -j MASQUERADE
-A POSTROUTING -o eth0 -j MASQUERADE
COMMIT
# Completed on Thu Nov 26 08:15:51 2015

9. Add a iptables file:

pi@raspsrv / $ cat /etc/iptables.ipv4.nat
pi@raspsrv $ sudo service hostapd start
pi@raspsrv $ sudo service isc-dhcp-server start

pi@raspsrv $ sudo service hostapd status
pi@raspsrv $ sudo service isc-dhcp-server status

pi@raspsrv $ sudo update-rc.d hostapd enable
pi@raspsrv $ sudo update-rc.d isc-dhcp-server enable

Third step

- Download, Install and Confiure DSLR Dashboard server (ddserver)

1. Clone GitHub reposiroty and compile:
pi@raspsrv $ pwd
/home/pi
pi@raspsrv $ git clone git://github.com/hubaiz/DslrDashboardServer package/DslrDashboardServer
pi@raspsrv $ cd package/DslrDashboardServer
pi@raspsrv $ sudo make menuconfig

pi@raspsrv $ sudo apt-get install build-essential pkg-config libusb-1.0-0-dev
pi@raspsrv $ sudo g++ -Wall src/main.cpp src/communicator.cpp `pkg-config --libs --cflags libusb-1.0` -lpthread -lrt -lstdc++ -o ddserver

2. Move to /usr/local/bin:

pi@raspsrv $ cd /home/pi/package
pi@raspsrv $ sudo mv DslrDashboardServer /usr/local/bin/DslrDashboardServer

/usr/local/bin/DslrDashboardServer/ddserver

- Create and add ddserver script on startup

pi@raspsrv /etc/init.d $ cat ddserver.sh
#!/bin/sh

### BEGIN INIT INFO
# Provides: ddserver
# Required-Start: $all
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: DslrDashboardServer daemon
# Description: Access and Control DSLR Cameras
### END INIT INFO

DIR=/usr/local/bin/DslrDashboardServer
DAEMON=$DIR/ddserver
DAEMON_NAME=ddserver
DAEMON_OPTS=""
DAEMON_USER=root

PIDFILE=/var/run/$DAEMON_NAME.pid

. /lib/lsb/init-functions

do_start () {
log_daemon_msg "Starting system $DAEMON_NAME daemon"
start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --chuid $DAEMON_USER --startas />$DAEMON -- $DAEMON_OPTS
log_end_msg $?
}
do_stop () {
log_daemon_msg "Stopping system $DAEMON_NAME daemon"
start-stop-daemon --stop --pidfile $PIDFILE --retry 10
log_end_msg $?
}

case "$1" in
start|stop)
do_${1}
;;
restart|reload|force-reload)
do_stop
do_start
;;
status)
status_of_proc "$DAEMON_NAME" "$DAEMON" && exit 0 || exit $?

;;
*)
echo "Usage: /etc/init.d/$DAEMON_NAME {start|stop|restart|status}"
exit 1
;;
esac
exit 0

pi@raspsrv $ cp -p ddserver.sh /etc/init.d
pi@raspsrv $ sudo chmod u+x /etc/init.d/ddserver.sh
pi@raspsrv $ sudo update-rc.d /etc/init.d/ddserver.sh defaults

pi@raspsrv $ cp your_script /etc/init.d/
pi@raspsrv $ sudo chmod u+x /etc/init.d/your_script
pi@raspsrv $ sudo update-rc.d /etc/init.d/your_script defaults

0 comentarios: