Difference between revisions of "Space state"

From Hackerspace ACKspace
Jump to: navigation, search
(derp)
(cleaned old space state page)
Line 5: Line 5:
 
}}
 
}}
  
[[User:Prodigity|Prodigity]] 23:34, 18 November 2014 (CET) Python script now doesn't crash and burn on failed connections
+
=== current implementation ===
 +
See [[ESP8266-SpaceState]] and [[SpaceAPI]].
  
 +
=== previous version ===
 +
==== notes ====
 +
* [[User:Prodigity|Prodigity]] 23:34, 18 November 2014 (CET) Python script now doesn't crash and burn on failed connections
 +
* [[User:Prodigity|Prodigity]] 23:23, 18 November 2014 (CET) The raspberry pi now mounts root as READ ONLY with the help of this tutorial (http://blog.pi3g.com/2014/04/make-raspbian-system-read-only/)
 +
*: This has been done to prevent corruption of the SD card.
 +
* [[User:Prodigity|Prodigity]] 02:34, 11 November 2014 (CET) Space state indicator now has a third state; "?"
 +
: A php script now periodically runs on the server to check when the spacestate has last been set;
 +
: if it is has been longer then 5 minutes it sets the state to "?".
 +
: This has been done to prevent power outages and loss of internet connection leaving an incorrect state.
  
[[User:Prodigity|Prodigity]] 23:23, 18 November 2014 (CET) The raspberry pi now mounts root as READ ONLY with the help of this tutorial
+
==== hardware ====
 
 
(http://blog.pi3g.com/2014/04/make-raspbian-system-read-only/)
 
 
 
This has been done to prevent corruption of the SD card.
 
 
 
 
 
[[User:Prodigity|Prodigity]] 02:34, 11 November 2014 (CET) Space state indicator now has a third state; "?"<br><br>
 
A php script now periodically runs on the server to check when the spacestate has last been set;<br>
 
if it is has been longer then 5 minutes it sets the state to "?".<br>
 
This has been done to prevent power outages and loss of internet connection leaving an incorrect state.<br>
 
 
 
'''Current setup'''
 
 
 
 
Vicarious and Prodigity have revived the SpaceState switch; It now uses a raspberry pi.
 
Vicarious and Prodigity have revived the SpaceState switch; It now uses a raspberry pi.
  
Line 34: Line 31:
 
Time is used to limit the amount of GPIO polls and more importantly, to limit the amount of network traffic.
 
Time is used to limit the amount of GPIO polls and more importantly, to limit the amount of network traffic.
  
TODO
+
==== code ====
*Insert <strike>python code and</strike> /etc/init.d/*.sh code
 
*Picture of current setup
 
 
 
 
<pre>
 
<pre>
 
#!/usr/bin/python
 
#!/usr/bin/python
Line 62: Line 56:
 
</pre>
 
</pre>
  
 
+
==== todo ====
 
+
* Insert <strike>python code and</strike> /etc/init.d/*.sh code
 +
* Picture of current setup
  
  
 
----
 
----
  
'''Previous setup'''
+
=== first version ===
 
+
The SpaceState switch is working fine now. This is how it's done:
  
<strike>For now we'll use our Skype account "ACK.space" to show whether the space is currently open or closed. Later we'll have a better set up.</strike>
+
==== hardware ====
 
+
We found a huge power switch which we mounted to the space wall this switch is connected with a cable to the Space-Mac using an serial to usb converter. On the Mac a perl scripts reads the space state. If the space-state changes, the perlscripts uses wget to call an php script on the ACKspace website. The php scripts sets an space-state variable in a file. The same script is used to read the space-state variable and show the status on the webpage.  
Although we forgot to update this page, the SpaceState switch is working fine now. This is how it's done
 
 
 
We found an huge powerswitch which we mounted to the space wall this switch is connected with a cable to the Space-Mac using an serial to usb converter. On the Mac a perl scripts reads the space state. If the space-state changes, the perlscripts uses wget to call an php script on the ACKspace website. The php scripts sets an space-state variable in a file. The same script is used to read the space-state variable and show the status on the webpage.  
 
 
 
<br>
 
  
 +
==== software ====
 
This is the perl script that does the thing on te Mac (note that this code is not yet the actual running version)
 
This is the perl script that does the thing on te Mac (note that this code is not yet the actual running version)
 
<pre>
 
<pre>
Line 131: Line 122:
 
</pre>
 
</pre>
  
[[Image:Spacestate switch.jpg|left|400px|Spacestate switch.jpg]][[Image:Spacestate closed.jpg|left|400px|Spacestate closed.jpg]]
+
==== pics or it didn't happen ====
 
+
<gallery>
[[Image:Spacestate open.jpg|left|400px|Spacestate open.jpg]]
+
Image:Spacestate switch.jpg|Spacestate switch
 +
Image:Spacestate closed.jpg|Spacestate closed
 +
Image:Spacestate open.jpg|Spacestate open
 +
<gallery>

Revision as of 13:56, 27 August 2015

Project: Space state
Featured:
State Completed, Fixed"Fixed" is not in the list (Active, Planned, Completed, Stalled, Impossible) of allowed values for the "State of Project" property.
Members Vicarious, xopr ( CoolePascal ), Prodigity
GitHub No GitHub project defined. Add your project here.
Description Show the current state (open or closed) of our space
Picture
No project picture! Fill in form Picture or Upload a jpeg here


current implementation

See ESP8266-SpaceState and SpaceAPI.

previous version

notes

A php script now periodically runs on the server to check when the spacestate has last been set;
if it is has been longer then 5 minutes it sets the state to "?".
This has been done to prevent power outages and loss of internet connection leaving an incorrect state.

hardware

Vicarious and Prodigity have revived the SpaceState switch; It now uses a raspberry pi.

The raspberry pi is currently running a python daemon which reads a GPIO pin every 10 seconds. This GPIO pin is connected to one end of the switch and a ground connection from the GPIO header is connected to another. When the switch is in the 'off' position the GPIO pin gets pulled up to +3.3v with the help of a 10K resistor, otherwise (when the switch is 'on') the GPIO pin gets pulled down.

The python script uses the RPi.GPIO, urllib2 and time library to accomplish its task. RPi.GPIO is used to easily read the GPIO pins from within python. urllib2 is used to post the spacestate to the website. Time is used to limit the amount of GPIO polls and more importantly, to limit the amount of network traffic.

code

#!/usr/bin/python
import time, urllib2
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(18, GPIO.IN)

# Check space switch for ever and ever ....
while 1:
        input_value = GPIO.input(18)
        if input_value == 1: # Space closed
                try:
                        bla = urllib2.urlopen('..')
                except:
                        print "Couldn't connect.."
        else:                # Space open
                try:
                        bla = urllib2.urlopen('..')
                except:
                        print "Couldn't connect.."
        print input_value # for debugging purposes..
        time.sleep(10) # Poll every 10 seconds..

todo

  • Insert python code and /etc/init.d/*.sh code
  • Picture of current setup



first version

The SpaceState switch is working fine now. This is how it's done:

hardware

We found a huge power switch which we mounted to the space wall this switch is connected with a cable to the Space-Mac using an serial to usb converter. On the Mac a perl scripts reads the space state. If the space-state changes, the perlscripts uses wget to call an php script on the ACKspace website. The php scripts sets an space-state variable in a file. The same script is used to read the space-state variable and show the status on the webpage.

software

This is the perl script that does the thing on te Mac (note that this code is not yet the actual running version)

   #!/usr/bin/perl -wT
   # Title    : spacestate.pl
   # Function : read spacestate switch en set action accordingly
   # Author   : Pascal Schiks (C) 2011

   #
   my $serialdev="/dev/tty.PL2303-000061FD";
   
   use strict;
   use IO::Handle;
   use Fcntl;

   my $TIOCMGET = 0x5415;

   my $spacestate=0;
   my $lastspacestate=$spacestate;
   while(1)
   {
      if(sysopen(SERIAL, $serialdev, O_RDWR))
      {
         my $mdmctl="";
         my $ioresult;
         unless(($ioresult=ioctl(SERIAL,  $TIOCMGET, $mdmctl))==-1)
         {
            $mdmctl = unpack('i',$mdmctl);
            $spacestate = ($mdmctl&64)==0 ? "open":"close";
            print "$spacestate\n" if($spacestate ne $lastspacestate);
         }
         else
         {
            print "Weet ik veel Error\n";
         }
         close(SERIAL);
         $lastspacestate = $spacestate;
      }
      else
      {
         print "Error, Could not open $serialdev\n";
      }
      sleep(1);
   }

Here to put the php script running on the webserver.

  <?php
      some code
  ?>

pics or it didn't happen

<gallery> Image:Spacestate switch.jpg|Spacestate switch Image:Spacestate closed.jpg|Spacestate closed Image:Spacestate open.jpg|Spacestate open <gallery>