Initial import
This commit is contained in:
commit
ca9fd8c2d7
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/config.py
|
22
README.md
Normal file
22
README.md
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
RICOH THETA m15 Remote for the WiPy
|
||||||
|
===================================
|
||||||
|
|
||||||
|
Use a [WiPy](http://wipy.io/) to connect to a [RICOH THETA](https://theta360.com/) camera
|
||||||
|
and trigger the shutter remotely.
|
||||||
|
|
||||||
|
As I'm using the Expansion Board, the shutter button is connected to GP17 and pulling the pin low.
|
||||||
|
A LED is connected to GP16.
|
||||||
|
|
||||||
|
|
||||||
|
Preparation
|
||||||
|
-----------
|
||||||
|
|
||||||
|
Copy the `config.example.py` to `config.py` and adjust the constants to your home wifi network.
|
||||||
|
|
||||||
|
|
||||||
|
Connecting to the THETA
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
When you switch on WiFi on your THETA, it creates a network called `THETA` followed by its serial
|
||||||
|
number, e.g. `THETAXN20123456`. The numeric part of the serial number is the password.
|
||||||
|
(Only if you didn't change it in the THETA app.)
|
14
boot.py
Normal file
14
boot.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# boot.py -- run on boot-up
|
||||||
|
# can run arbitrary Python, but best to keep it minimal
|
||||||
|
|
||||||
|
# Copy config.example.py to config.py and modify to your needs first!
|
||||||
|
import config
|
||||||
|
|
||||||
|
from network import WLAN
|
||||||
|
wifi = WLAN(WLAN.STA)
|
||||||
|
wifi.connect(config.HOME_SSID, auth=(WLAN.WPA, config.HOME_PASSWORD))
|
||||||
|
|
||||||
|
from machine import UART
|
||||||
|
from os import dupterm
|
||||||
|
uart = UART(0, baudrate=115200)
|
||||||
|
dupterm(uart)
|
4
config.example.py
Normal file
4
config.example.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# modify and rename to config.py
|
||||||
|
|
||||||
|
HOME_SSID = 'MyHomeNetwork'
|
||||||
|
HOME_PASSWORD = 'ultrasecret!'
|
33
main.py
Normal file
33
main.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
# main.py -- put your code here!
|
||||||
|
|
||||||
|
from machine import Pin
|
||||||
|
import time
|
||||||
|
import theta
|
||||||
|
|
||||||
|
led = Pin("GP16", Pin.OUT)
|
||||||
|
|
||||||
|
led.toggle()
|
||||||
|
|
||||||
|
def log(msg):
|
||||||
|
print(msg)
|
||||||
|
|
||||||
|
def btnPressed(pin):
|
||||||
|
led.toggle()
|
||||||
|
time.sleep_us(100)
|
||||||
|
|
||||||
|
btn = Pin("GP17", Pin.IN, Pin.PULL_UP)
|
||||||
|
btn.irq(trigger=Pin.IRQ_FALLING, handler=btnPressed)
|
||||||
|
|
||||||
|
def home():
|
||||||
|
global wifi
|
||||||
|
wifi.connect(config.HOME_SSID, auth=(WLAN.WPA, config.HOME_PASSWORD))
|
||||||
|
|
||||||
|
def tc():
|
||||||
|
global t, p
|
||||||
|
t = theta.Theta()
|
||||||
|
p = t.connect()
|
||||||
|
if not p:
|
||||||
|
print("Connect failed!")
|
||||||
|
else:
|
||||||
|
answer = p.initCommand(b'1234567812345678', b'W\x00i\x00P\x00y\x00')
|
||||||
|
print(answer)
|
36
ptpip.py
Normal file
36
ptpip.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
"""
|
||||||
|
PTP/IP class for MicroPython
|
||||||
|
@author Markus Birth <markus@birth-online.de>
|
||||||
|
"""
|
||||||
|
import socket
|
||||||
|
import struct
|
||||||
|
|
||||||
|
class PTPIP:
|
||||||
|
def __init__(self, ipadr):
|
||||||
|
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
self.socket.connect((ipadr, 15740))
|
||||||
|
self.socket.setblocking(1) # wait for answer
|
||||||
|
|
||||||
|
def createPkg(self, pktype, payload):
|
||||||
|
pklen = len(payload) + 8
|
||||||
|
pkg = struct.pack('<I', pklen) + struct.pack('<I', pktype) + payload
|
||||||
|
return pkg
|
||||||
|
|
||||||
|
def recvPkg(self):
|
||||||
|
pklen = self.socket.recv(4)
|
||||||
|
pklen_int = struct.unpack('<I', pklen)[0]
|
||||||
|
print("Incoming: %i bytes" % pklen_int)
|
||||||
|
pktype = self.socket.recv(4)
|
||||||
|
pktype_int = struct.unpack('<I', pktype)[0]
|
||||||
|
print("Packet type: %i" % pktype_int)
|
||||||
|
payload = self.socket.recv(pklen_int - 8)
|
||||||
|
return (pktype_int, payload)
|
||||||
|
|
||||||
|
def getSocket(self):
|
||||||
|
return self.socket
|
||||||
|
|
||||||
|
def initCommand(self, guid, identifier):
|
||||||
|
pkg = self.createPkg(1, str.encode(guid[:16]) + str.encode(identifier))
|
||||||
|
self.socket.send(pkg)
|
||||||
|
result = self.recvPkg()
|
||||||
|
return result
|
41
theta.py
Normal file
41
theta.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
"""
|
||||||
|
RICOH Theta class for MicroPython
|
||||||
|
|
||||||
|
@author Markus Birth <markus@birth-online.de>
|
||||||
|
"""
|
||||||
|
|
||||||
|
from network import WLAN
|
||||||
|
import ptpip
|
||||||
|
|
||||||
|
class Theta:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.wlan = WLAN(WLAN.STA)
|
||||||
|
pass
|
||||||
|
|
||||||
|
def log(self, msg):
|
||||||
|
print(msg)
|
||||||
|
|
||||||
|
def findWifi(self):
|
||||||
|
wlans = self.wlan.scan()
|
||||||
|
for w in wlans:
|
||||||
|
if w.ssid.startswith('THETA'):
|
||||||
|
self.log('Found Theta WiFi: %s' % w.ssid)
|
||||||
|
return w.ssid
|
||||||
|
return False
|
||||||
|
|
||||||
|
def connectWifi(self, ssid):
|
||||||
|
password = ssid[-8:]
|
||||||
|
return self.wlan.connect(ssid, auth=(WLAN.WPA, password))
|
||||||
|
|
||||||
|
# convenience - might get removed
|
||||||
|
def connect(self):
|
||||||
|
wifi = self.findWifi()
|
||||||
|
if not wifi:
|
||||||
|
return False
|
||||||
|
self.connectWifi(wifi)
|
||||||
|
self.ptpip = ptpip.PTPIP('192.168.1.1')
|
||||||
|
return self.ptpip
|
||||||
|
|
||||||
|
def getPTPIP(self):
|
||||||
|
return self.ptpip
|
Loading…
x
Reference in New Issue
Block a user