#!/usr/bin/python
import socket
import struct
import fcntl
importsubprocess
import sys
MCAST_GRP ='224.1.1.1'
MCAST_PORT =5007
sock =socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR, 1)
sock.bind(('',MCAST_PORT))
mreq =struct.pack("4sl", socket.inet_aton(MCAST_GRP), socket.INADDR_ANY)
sock.setsockopt(socket.IPPROTO_IP,socket.IP_ADD_MEMBERSHIP, mreq)
defget_ip_address(ifname):
s =socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
returnsocket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, #SIOCGIFADDR
struct.pack('256s',ifname[:15])
)[20:24])
id =get_ip_address('eth0')
ip1, ip2, ip3,ip4 = id.split('.')
print 'ID: ' ip4'-'
optionfile =open('/server/options.cfg','r')
options =optionfile.readline()
optionfile.close()
print"optons: " options
while True:
data =sock.recv(10240)
data =data.strip()
if data =="reboot":
print"rebooting..."
cmd = 'sudoreboot'
pid = subprocess.call(cmd,shell=True)
elif data =="reload":
optionfile =open('/server/options.cfg','r')
options =optionfile.readline()
optionfile.close()
elif data =="restart":
cmd ='/server/reload.sh&'
pid =subprocess.call(cmd, shell=True)
else:
print "shooting" data
cmd ='raspistill -o /tmp/photo.jpg ' options
pid =subprocess.call(cmd, shell=True)
print"creating directory"
cmd = 'mkdir/server/3dscan/' data
pid =subprocess.call(cmd, shell=True)
print "copyimage"
cmd = 'cp/tmp/photo.jpg /server/3dscan/' data "/" data "_" ip4'.jpg'
pid =subprocess.call(cmd, shell=True)
print"photo uploaded"