User:EmbeddedLinuxGuy: Difference between revisions

From Noisebridge
Jump to navigation Jump to search
No edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= table =
{| class="wikitable collapsible"
! Simple collapsible table
|-
| Lorem ipsum dolor sit amet
|}
= ssh public key =
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxmitrXxenyJDjEhVCNeBDMtV0+yuXGVrb0qO/e9LxiB0w255JvX/iDWtLqaeu7DriwK9yiCM6UXUp3gnhUUXIDvs5cljXRDlLbm9ziq5fumh0r+AvlDMRejFwxCSNuucY0/vkaY0Ow1CzlecixFjZ77tCygbqm/az++D0+KpRavyvLyVXiSpdEbJFKpq5RTdk4ht7DpMxHKJC7h3FCoNB9N3B7H+dUGmTx3JKwAJ5uHeOpV8wKrTQco/6SlROl2zBBIsllvbniYuBZ5uhK1qWc8CFEaH6yi4MM20SB/qQpCn/G/1/RdlW1Qks8sy5uMmSXP1FA0FtaRuhAi+gSoaDw== embeddedlinuxguy@gmail.com
= bio =
I mostly do programming for Linux and the Web, but also like to tinker with an Arduino and soldering iron when I have the chance.
I mostly do programming for Linux and the Web, but also like to tinker with an Arduino and soldering iron when I have the chance.


jesse@
= art =


ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxmitrXxenyJDjEhVCNeBDMtV0+yuXGVrb0qO/e9LxiB0w255JvX/iDWtLqaeu7DriwK9yiCM6UXUp3gnhUUXIDvs5cljXRDlLbm9ziq5fumh0r+AvlDMRejFwxCSNuucY0/vkaY0Ow1CzlecixFjZ77tCygbqm/az++D0+KpRavyvLyVXiSpdEbJFKpq5RTdk4ht7DpMxHKJC7h3FCoNB9N3B7H+dUGmTx3JKwAJ5uHeOpV8wKrTQco/6SlROl2zBBIsllvbniYuBZ5uhK1qWc8CFEaH6yi4MM20SB/qQpCn/G/1/RdlW1Qks8sy5uMmSXP1FA0FtaRuhAi+gSoaDw== embeddedlinuxguy@gmail.com
[[Media:Stars-small.svg|Stars SVG]]
 
=Stuff=
<pre>
import serial
import urllib
import sys
if sys.version_info >= (3, 0):
import urllib.request
gui = 0
else:
gui = 1
from time import strftime, gmtime, sleep
 
# mode 0=error, 1-5
# door 0=closed 1=open
# gate 0=closed 1=open
# laser beam 0=fine 1=interrupted
# wire 0=fine 1=interrupted
# keypad 0=nothing/1=good/2=bad password
# code string-of-digits (5 or more)
 
PAUSE_SERIAL = 0
 
if gui:
import wx
ID_START = wx.NewId()
class Frame(wx.Frame):
def __init__(self, title):
wx.Frame.__init__(self, None, title=title, size=(350,200))
panel = wx.Panel(self)
box = wx.BoxSizer(wx.VERTICAL)
m_text = wx.StaticText(panel, -1, "Box Shop Alarm Control")
m_text.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))
m_text.SetSize(m_text.GetBestSize())
box.Add(m_text, 0, wx.ALL, 10)
 
self.m_status = wx.StaticText(panel, -1, "")
self.m_open = wx.Button(panel, ID_START, "Start")
self.m_close = wx.Button(panel, wx.ID_CLOSE, "Stop")
self.m_buzz = wx.Button(panel, wx.ID_CLOSE, "Buzz")
self.m_close.Bind(wx.EVT_BUTTON, self.OnClose)
self.m_open.Bind(wx.EVT_BUTTON, self.OnStart)
self.m_buzz.Bind(wx.EVT_BUTTON, self.OnBuzz)
box.Add(self.m_open, 0, wx.ALL, 10)
box.Add(self.m_close, 0, wx.ALL, 10)
box.Add(self.m_buzz, 0, wx.ALL, 10)
panel.SetSizer(box)
panel.Layout()
self.m_close.Disable()
def OnClose(self, event):
self.RUN_SERIAL = 0
self.m_close.Disable()
self.m_open.Enable()
def OnStart(self, event):
self.m_open.Disable()
self.m_close.Enable()
self.handleSerial()
def OnBuzz(self, event):
self.RUN_SERIAL = 2
def handleSerial(self):
self.RUN_SERIAL = 1
ser = serial.Serial(2, 9600, timeout=1)
outputs = {'M': '0', 'D': '0', 'G': '0', 'B': '0', 'W': '0', 'K': '0', 'C': '0'}
while self.RUN_SERIAL:
if self.RUN_SERIAL == 2:
self.m_status.SetLabel("WE ARE BUZZING!!!!")
s = ".D1"
if (s):
ser.write(s)
self.m_status.SetLabel("We buzzed.")
self.RUN_SERIAL = 1
else:
value = ser.readline().decode('utf-8')
if value:
for v in value.strip('{}').split('}{'):
outputs[v[0]] = v[1:]
url = "http://www.waywardengineer.com/boxshop/alarmapi.php?"
for k, v in outputs.items():
url += k + '=' + v + '&'
outputs['K'] = '0'
outputs['C'] = '0'
self.m_status.SetLabel(url)
#print(url)
try:
if sys.version_info >= (3, 0):
f = urllib.request.urlopen(url)
else:
f = urllib.urlopen(url)
s = f.read()
#print (s)
if (s):
ser.write(s)
except Exception as inst:
print("Got an error contacting the web " + strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))
print(type(inst))
print(inst.args)
print(inst)
sleep(1)
wx.Yield()
app = wx.App(redirect=True)
top = Frame("Box Shop Alarm Control")
top.Show()
app.MainLoop()
else:
class SerialWebBridge:
def handleSerial(self):
self.RUN_SERIAL = 1
ser = serial.Serial(2, 9600, timeout=1)
outputs = {'M': '0', 'D': '0', 'G': '0', 'B': '0', 'W': '0', 'K': '0', 'C': '0'}
while self.RUN_SERIAL:
value = ser.readline().decode('utf-8')
if value:
for v in value.strip('{}').split('}{'):
outputs[v[0]] = v[1:]
url = "http://www.waywardengineer.com/boxshop/alarmapi.php?"
for k, v in outputs.items():
url += k + '=' + v + '&'
outputs['K'] = '0'
outputs['C'] = '0'
print(url)
try:
if sys.version_info >= (3, 0):
f = urllib.request.urlopen(url)
else:
f = urllib.urlopen(url)
s = f.read()
print (s)
if (s):
ser.write(s)
except Exception as inst:
print("Got an error contacting the web " + strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))
print(type(inst))
print(inst.args)
print(inst)
sleep(1)
 
bridge = SerialWebBridge()
bridge.handleSerial()
</pre>

Latest revision as of 20:14, 18 September 2012

table[edit]

Simple collapsible table
Lorem ipsum dolor sit amet

ssh public key[edit]

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxmitrXxenyJDjEhVCNeBDMtV0+yuXGVrb0qO/e9LxiB0w255JvX/iDWtLqaeu7DriwK9yiCM6UXUp3gnhUUXIDvs5cljXRDlLbm9ziq5fumh0r+AvlDMRejFwxCSNuucY0/vkaY0Ow1CzlecixFjZ77tCygbqm/az++D0+KpRavyvLyVXiSpdEbJFKpq5RTdk4ht7DpMxHKJC7h3FCoNB9N3B7H+dUGmTx3JKwAJ5uHeOpV8wKrTQco/6SlROl2zBBIsllvbniYuBZ5uhK1qWc8CFEaH6yi4MM20SB/qQpCn/G/1/RdlW1Qks8sy5uMmSXP1FA0FtaRuhAi+gSoaDw== embeddedlinuxguy@gmail.com

bio[edit]

I mostly do programming for Linux and the Web, but also like to tinker with an Arduino and soldering iron when I have the chance.

art[edit]

Stars SVG

Stuff[edit]

import serial
import urllib
import sys
if sys.version_info >= (3, 0):
	import urllib.request
	gui = 0 
else:
	gui = 1
from time import strftime, gmtime, sleep

# mode 0=error, 1-5
# door 0=closed 1=open
# gate 0=closed 1=open
# laser beam 0=fine 1=interrupted
# wire 0=fine 1=interrupted
# keypad 0=nothing/1=good/2=bad password
# code string-of-digits (5 or more)

PAUSE_SERIAL = 0

if gui:
	import wx
	ID_START = wx.NewId()
	class Frame(wx.Frame):
		def __init__(self, title):
			wx.Frame.__init__(self, None, title=title, size=(350,200))
			panel = wx.Panel(self)
			box = wx.BoxSizer(wx.VERTICAL)
			m_text = wx.StaticText(panel, -1, "Box Shop Alarm Control")
			m_text.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))
			m_text.SetSize(m_text.GetBestSize())
			box.Add(m_text, 0, wx.ALL, 10)

			self.m_status = wx.StaticText(panel, -1, "")
			self.m_open = wx.Button(panel, ID_START, "Start")
			self.m_close = wx.Button(panel, wx.ID_CLOSE, "Stop")
			self.m_buzz = wx.Button(panel, wx.ID_CLOSE, "Buzz")
			self.m_close.Bind(wx.EVT_BUTTON, self.OnClose)
			self.m_open.Bind(wx.EVT_BUTTON, self.OnStart)
			self.m_buzz.Bind(wx.EVT_BUTTON, self.OnBuzz)
			box.Add(self.m_open, 0, wx.ALL, 10)
			box.Add(self.m_close, 0, wx.ALL, 10)
			box.Add(self.m_buzz, 0, wx.ALL, 10)
			panel.SetSizer(box)
			panel.Layout()
			self.m_close.Disable()
						
		def OnClose(self, event):
			self.RUN_SERIAL = 0
			self.m_close.Disable()
			self.m_open.Enable()
			
		def OnStart(self, event):
			self.m_open.Disable()
			self.m_close.Enable()
			self.handleSerial()
			
		def OnBuzz(self, event):
			self.RUN_SERIAL = 2
			
		def handleSerial(self):
			self.RUN_SERIAL = 1
			ser = serial.Serial(2, 9600, timeout=1)
			outputs = {'M': '0', 'D': '0', 'G': '0', 'B': '0', 'W': '0', 'K': '0', 'C': '0'}
			
			while self.RUN_SERIAL:
				if self.RUN_SERIAL == 2:
					self.m_status.SetLabel("WE ARE BUZZING!!!!")
	
					s = ".D1"
					if (s):
						ser.write(s)
										
					self.m_status.SetLabel("We buzzed.")
					self.RUN_SERIAL = 1
				else:
					value = ser.readline().decode('utf-8')
					if value:
						for v in value.strip('{}').split('}{'):
							outputs[v[0]] = v[1:]
						url = "http://www.waywardengineer.com/boxshop/alarmapi.php?"
						for k, v in outputs.items():
							url += k + '=' + v + '&'
						outputs['K'] = '0'
						outputs['C'] = '0'
						self.m_status.SetLabel(url)
						#print(url)	
						try:
							if sys.version_info >= (3, 0):
								f = urllib.request.urlopen(url)
							else:
								f = urllib.urlopen(url)
							s = f.read()
							#print (s)
							if (s):
								ser.write(s)
						except Exception as inst:
							print("Got an error contacting the web " + strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))
							print(type(inst))
							print(inst.args)
							print(inst)
							sleep(1)
				wx.Yield()
									
	app = wx.App(redirect=True)
	top = Frame("Box Shop Alarm Control")
	top.Show()
	app.MainLoop()
else:
	class SerialWebBridge:
		def handleSerial(self):
			self.RUN_SERIAL = 1
			ser = serial.Serial(2, 9600, timeout=1)
			outputs = {'M': '0', 'D': '0', 'G': '0', 'B': '0', 'W': '0', 'K': '0', 'C': '0'}
			while self.RUN_SERIAL:
				value = ser.readline().decode('utf-8')
				if value:
					for v in value.strip('{}').split('}{'):
						outputs[v[0]] = v[1:]
					url = "http://www.waywardengineer.com/boxshop/alarmapi.php?"
					for k, v in outputs.items():
						url += k + '=' + v + '&'
					outputs['K'] = '0'
					outputs['C'] = '0'
					print(url)	
					try:
						if sys.version_info >= (3, 0):
							f = urllib.request.urlopen(url)
						else:
							f = urllib.urlopen(url)
						s = f.read()
						print (s)
						if (s):
							ser.write(s)
					except Exception as inst:
						print("Got an error contacting the web " + strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))
						print(type(inst))
						print(inst.args)
						print(inst)
						sleep(1)

	bridge = SerialWebBridge()
	bridge.handleSerial()