piBeacon: 3- presence monitoring download

Posted on
Fri Jan 29, 2016 1:54 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: piBEACON: presence monitoring download

posted v 1.6.1

fixed:
loopMaxCallBLE variable ws handled incorrectly

added:
added ALIVE signal from rPi to plugin if there are no bluetooth messages. ==> rPi should not expire

Karl

Posted on
Sun Jan 31, 2016 11:20 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: piBEACON: presence monitoring download

v 1.7.1 posted:

fixed:
the menue/configuration screen forgot previous settings, now it remembers


added:
support of dallas1Wire sensors (right now only temp, others will be added later when I get them, my DHT22 temp+humidity died )

The plugin does ALL necessary software config on the rPi, see http://forums.indigodomo.com/viewtopic.php?f=187&t=15563 for more detail how to connect.


Karl

Posted on
Sat Feb 06, 2016 3:43 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: piBEACON: presence monitoring download

v-1.8.1 posted


FIXED:
smaller issues (e.g. logging on rPi)

ADDED;
1. support for various sensors (temp, humidity, pressure) and digital input. You can use buttons-switches or e.g. garage door sensors etc to trigge.
  • OneWire DS18B20 temperature sensor $1- $5
  • DHT 11 & DHT22 temperature and humidity sensor $4-$10
  • BMP085 and equiv i2c Temperature & pressure sensor $5 - $10
  • 6 digital input buttons either simple buttons or electric switches/relays etc, reaction time between button press and indigo state changes: < 0.5 seconds, I did not see any delay
  • on list to be tested: BME280 (temP+humidity+Pressure)and MCP9808 (precision temperature)
Units for temp and pressure can be set in configuration


2. GPIO output pins to drive e.g. LED, switches etc. 3-9 (rPi1 vs rPi2) GPIO pins
Supported functions:
  1. on/ off,
  2. single pulse ON for x seconds
  3. single pulse OFF for x seconds
  4. continuous pulse up/down for x/y seconds for n periods eg for blinking LED
reaction time: indigo action to rPI GPIOpin changes < 0.5 seconds
the rPis will remember the states of the output GPIOs and will restore UP or DOWN states of the GPIOs after reboot
The pins can be set from menu, action or python script

All necessary software will be automatically loaded onto the rPis and configured (it might take 5 minutes initially)

All of above can be connected at the same time including iBeacon detector function (tested on rPi2 don't know if all of them will work at the same time on the rPi1)

Some of the functions (i.e. faster reaction to input) are better than on the arduino-plugin. Only the analog input / output functions are not present. And with rPI2 @ $5(+wifi+..) this becomes really cost competitive.


A HOW TO use sensors and output GPIOs :http://forums.indigodomo.com/viewtopic.php?f=187&t=15563

Karl

Posted on
Tue Feb 09, 2016 5:20 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: piBEACON: presence monitoring download

v 1.9.1 posted

fixed:
DHT sensor did not work properly


added
now the following sensors are supported:
  1. oneWire18B20-- Temp
  2. DHTxx -- Temp & Humidity
  3. i2cBMPxx -- Temp & Pressure
  4. i2cTMP102 -- Temp
  5. i2cMCP9808 -- Temp
  6. i2cT5403 -- Temp & Pressure
  7. i2cBMExx Temp & Pressure& Humidity
prices between $1 and $20 at amazon with various form factors and precessions. you can use 2 of the sensors at the same time and will get 2 measurements e.g. Temperature and Temperature2
As for TEMP/Pressure/Humidity that should be it.

Added states "OUTPUT_x" to the states. It shows the current UP/DOWN/PULSE etc status of the GPIO OUTPUT bins.

Changed names of INPUT states from BUTTON to INPUT .. which makes more sense

added for output GPIOS 2 schemas: GPIO numbering or sequential 0..8, your choice

Worked on edges of menus etc to make things smoother.

Future: I will add
1. analog inputs to be able to cover all the analog sensors, e.g. measure soil humidity, gas quality, water level, pressure sensors...
2. Luminosity sensor
3. May be sone specialized sensors when I come across them
4. We could add a counter mode for the INPUT GPIO-pins for e.g. Energy measurement, rain rate/ volume measurements etc.

With the current setup you can do most inputs e.g. magnetic door sensors: connect the switch to one of the enabled GPIO-INPUT pins and ground and you will have a < 0.5 secs response time of the device state change for the magnetic switch.

==> will add a how to to the ipBEACON sensor thread.

Don't know what else to add.

Karl

I now have 12 rPis running
next project with rPI: is FING on rPi and load the info into fingscan to off load the FING low level stuff from the MAC

Posted on
Fri Feb 12, 2016 10:46 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: piBEACON: presence monitoring download

version 1.10.1 posted

fixed
made some menu fixes, behind the scenes fixes


added/changed
SENSORs and OUTPUTs are now separated from the iBeacons code.
Each sensor will be its own indigo device e.g. DHTxx sensors will have states "temperature" and "pressure".
The rPis will NOT have any sensors states in its device. That makes the whole thing smaller as not all states of all potential sensors have to be created in the rPis while only 1 or 2 are used.

This now enables to add new sensors very easily, just 3 places have to be added / modified to capture any new sensors.

Karl

Posted on
Sun Feb 14, 2016 6:30 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: piBEACON: presence monitoring download

new raspberry SSD image (with 4 GBYTE) posted
==> easier download, any 8GB SSD should work, BUT you need to expand the disk on the rPI, see SSD thread on how to. The disk is 99.9% full at 4GB. but with "sudo pass-config" you can expand it to 8GB after booting the rPi.
For those who had problems using the SSD and getting error messages when starting the rPi = did not boot

V1.10.2

fixed:
- copy from mac to raspberry does not work on OS X 10.6, fixed
- A warning error message suppressed if it can find a file which is normal when you start
- the output function had some problems. Fixed

added:
analog value output to GPIO pins. This is a simulated analog value through PWM (duty cycles e.g. 20ms up 80 ms down ==> 3.3V * 0.2 ~=0.66V)


Karl

Posted on
Mon Feb 15, 2016 1:12 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: piBEACON: presence monitoring download

posted v 1.10.3

fixed:
piBeacon indigo device folder was not created

Posted on
Sun Feb 28, 2016 11:47 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: piBEACON: presence monitoring download

posted V 1.11.1 at top of this thread

fixed:
some menu issues, under the hood things.


added
  • the GPIO input pins can now besides show on/off be used as a counter. Every time the pin goes from 0 to1 the pin counter is increased by one. This can be used for electricity / water ... monitors. in the menu or through an action you can reset the counter.
  • support for SPI type inout/output devices i.e. the 8 channel analog input MCP3008. This adds 8 channels with 10 bit analog voltage resolution input. You can use this to measure any voltage between 0 .. 3.3 V
  • support for 4 channel 16 bit ADS1x15 analog input device. Tt can measure voltages between 0 and 5 volts.
  • support for multiple i2c devices of the same type. If you can set a different i2c address you could have as many e.g. tmp102 etc devices as you like connected.
  • support for Digital to Analog Converter (DAC) output device MCP4725. It offers a 12 bit DAC to set an output voltage between 0..5 volts. The output voltage can be set in the menu, an action, in a python script, or plugin.
  • for analog input devices you now can automate the calculation of the resistor attached device e.g. a thermistor, photo element etc. You give feed voltage and feed resistor and the plugin will show the value of the resistor-sensor in Ohm. It (hopefully) calculates the the value of the sensor with ohms law from 2 resistors in series and the feed voltage by measuring the voltage at the sensor.
  • the status display value can now be calculated : you can add an offset and multiply the value to your liking and choose a format for the number and add a unit to it.
    E.g. you could measure voltage of a humidity sensor in the soil and show 45%, or use a bend sensor and show 30º or 77 inches or 1.35 [Lux] etc.


All of the i2c sensor can be connected in parallel with 4 cables (V+, Gnd, SDA,SDC) if they have a different i2c address. I tried 6 and it worked

WARNING: do n ot connect +5Volts to a GPIO pin. The rPi dies immediately!!I tested that and it works, reaction time < 0.1 seconds :(

More details on input and output devices in the sensor section of piBeacon.


Karl

Posted on
Tue Mar 01, 2016 10:24 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: piBEACON: presence monitoring download

v 1.12.1 posted

fixed:
- some menu language and clean up
- the resistor calculation had a bug: used yy/max (xx,00001) instead of yy/max(xx, 0.0001) (my eyesight is not that great anymore)


added
the plugin now supports a freely configurable "mysensor.py" program that runs on the rPi and can populate states of a device in indigo
You will need to rename and change the program "renameMeTo_sensors.py" (on the rPi) and put your logic in there.
"renameMeTo_sensors.py" will appear on the rPi once you load the new plugin.
In order to use it you have to create a device with type "INPUT-my sensors.py program" in the plugin like any other sensor device.
You can set a parameter in the config (address). That parameter will be available to the mysensors.py file on the rPi, you can use it or ignore it.
If a device is created and active mysensors.py will be launched and will populate the appropriate files which will be send to the plugin and shown as INPUT_0 .._9 in the device states.
The example file "renameMeTo_sensors.py" gives a simple example how to send e.g. the current timestamp to Indigo in INPUT_0 and some other constants in the other states.

THIS IS FOR FOLKS THAT CAN WRITE PYTHON CODE, but it should not be difficult if you know a little py.

Karl


attached the example code. If you have questions, happy to help.

Code: Select all
#!/usr/bin/python
# by Karl Wachs
# march 1 2016
# exampel program to get data and send it to indigo
import  sys, os, time, json, datetime,subprocess,copy

# ===========================================================================
# utils
#  ===========================================================================


def toLog(lvl,msg):
        global debug, homeDir
        if lvl < debug :
            f = open(homeDir+"mysensors.log","a")
            f.write(datetime.datetime.now().strftime("%Y%m%d-%H:%M:%S")+" "+msg+"\n")
            f.close()
def killOldPgm(myPID,pgmToKill):
        global debug, homeDir
        try:
            cmd= "ps -ef | grep "+pgmToKill+" | grep -v grep"
            ret = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()[0]
            lines =ret.split("\n")
            for line in lines:
                if len(line) < 10: continue
                line =line.split()
                pid = int(line[1])
                if pid == int(myPID): continue
                toLog(-1, "killing "+pgmToKill)
                os.system("sudo kill -9 "+str(pid))
        except  Exception, e:
            toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))



# ===========================================================================
# sensor start
# ===========================================================================

def startMySensors(addr=0):
        global cAddress
        try:
            # do your init here
            parameter= cAddress[addr]
            ## add any inti code here for address # addr
            toLog(-1, u"starting my sensors "+ unicode(cAddress)+";    dev= "+unicode(addr))
        except  Exception, e:
            toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
            toLog(-1, u"channel used: "+ unicode(cAddress)+";    addr= "+unicode(addr))

def getMySensors(addr=0):
        global cAddress
        try:
            parameter= cAddress[addr]
            v = ["","","","","","","","","","",]#set return to empty
            # do your stuff here, this if for testing to something into the data
            x = time.time()
            v = [str(x),str(x/2),"0","1","2","3","4","5","6","7"]
            return v
        except  Exception, e:
            toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
        return ""

       
# ===========================================================================
# sensor end
# ===========================================================================

# ===========================================================================
# read params
# ===========================================================================
def readParams():
        global debug, homeDir,sensorList,cAddress,sensorRefreshSecs
        f=open(homeDir+"parameters","r")
        lines=f.read().strip("\n").split("\n")
        f.close()

        sensorList  = "0"
        cAddressOld = copy.copy(cAddress)
        cAddress    = {}


        f=open(homeDir+"parameters","r")
        inp =json.loads(f.read())
        f.close()

        if "debug"              in inp:  debug =                  int(inp["debug"])
        if "sensorList"         in inp:  sensorList =                (inp["sensorList"])
        if "sensorRefreshSecs"  in inp:  sensorRefreshSecs =    float(inp["sensorRefreshSecs"])/1.5
        if "cAddress"           in inp:  xxx =                        inp["cAddress"]

        if sensorList.find("mysensors") == -1: return
        if "mysensors" not in xxx: return

        same=True
        cAddress= copy.copy(xxx["mysensors"])

        # check if anything new
        if "mysensors" not in cAddressOld:
            same=False
        else:
            for addr in cAddress:
                if addr not in cAddressOld:
                        same=False
                        break
                elif len(cAddress) != len(cAddressOld):
                        same=False
                        break
                if cAddressOld[addr] != cAddress[addr]:
                        same=False
                        break
   
        if not same: # if anything new start appropriate pgms
            # delete old data file
            if os.path.isfile(homeDir+"mysensors.dat"):
                os.remove(homeDir+"mysensors.dat")
            # start each "channel, device or what every you like to do
            for addr in cAddress:
                startMySensors(addr=addr)




# ===========================================================================
# Main
# ===========================================================================


global debug, homeDir,sensorList, externalSensor,cAddress,sensorRefreshSecs

debug             = 5 # will be overwritten in readParams
homeDir           = "/home/pi/"
nInputs           = 10 # number of input channels 1...10 max

loopCount         = 0  # for loop,  not used could be deleted, but you might need it
sensorRefreshSecs = 33 # will be overwritten in readParams, number of seconds to sleep in each loop
sensorList        = "" # list of sensor, we are looking for "mysensors"
cAddress          = [] # store address / parameters we get from indigo in device config of mysensors in readParams

readParams()           # get parameters send from indigo

myPID             = str(os.getpid())
killOldPgm(myPID,"mysensors.py")# kill old instances of myself if they are still running

lastData ={}
while True:  # loop for ever
        data={}
        try:
            ### get data
            if sensorList.find("mysensors") > -1:# do mysensor
                for  nAddr in range(len(cAddress)):
                    v = getMySensors(addr=nAddr)
                    if v != "":
                        addr = cAddress[nAddr]
                        data["mysensors"] = {}
                        data["mysensors"][addr] = { }
                        for ii in range(min(nInputs,len(v))):
                            data["mysensors"][addr]["INPUT_"+str(ii)]  = v[ii]
            loopCount +=1

            #  write data in proper format to output file
            if data != {} and lastData != data:
                lastData =copy.copy(data)
                f=open(homeDir+"mysensors.dat","w") # this is the file that wil be used to compose the message to indigo, read by sensors.py
                f.write(json.dumps(data))  #  looks like: {"mysensors":{"2":{"INPUT_0":123,"INPUT_1":22,..,"INPUT_9":99}}, where "2" is the address parameter we got from indigo
                f.close()
        except  Exception, e:
            toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))

        time.sleep(sensorRefreshSecs) # sleep the requested amount
        readParams()  # check if we have new parameetrs

sys.exit(0)       
 

Posted on
Wed Mar 02, 2016 3:01 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: piBEACON: presence monitoring download

v 1.12.10 posted


fixed:
when upgrading fro an older version things got messed up. thanks to wouterK for debugging.



added
now supports the brother / sister to mysensor.py. i.e. myoutput.py.
The plugin will add a file renameMeTo_myoutput.py to the rPi. It has an example how to use the tool, see attached
You can either use the menu command or an action or an action script to send a command to the program myoutput.py

the python script would look like:
##
Code: Select all
plug = indigo.server.getPlugin("com.karlwachs.piBeacon")
if not plug.isEnabled(): return   #### piBeacon  must be enabled, otherwise nothing here works
plug.executeAction("myoutput",
   props ={
    "piServerNumber": "0"  ##  rPi server #  0...9
    ,"text":   "'gpio 21 high'"  # use ' inside to send it to sys.arv[1] as one string otherwise it will be split into each word ie sys.argv[2].. [x]
      }
   )
##will set gip # 21 high, see the my output.py code.
##or
plug.executeAction("myoutput",
   props ={
    "piServerNumber": "0"  ##  rPi server #  0...9
    ,"text":   "'reboot'"  # use ' inside to send it to sys.arv[1] as one string otherwise it will be split into each word ie sys.argv[2].. [x]
      }
   )
##would reboot the rPi


will set gip # 21 high, see the my output.py code.
Karl




Code: Select all
# by Karl Wachs
# march 2
# this program will be called if indigo plugin sends a myoutput command
##
import json, sys,subprocess, time,datetime,os

## ===========================================================================
# utils
#  ===========================================================================

def readParams():
        global debug, homeDir
        f=open(homeDir+"parameters","r")
        inp =json.loads(f.read())
        f.close()
        if "debug"              in inp:  debug=             int(inp["debug"])

def toLog(lev, text):
        global  debug, homeDir
        if lev <= debug:
            logF=open(homeDir+"myoutput.log","a")
            logF.write(datetime.datetime.now().strftime("%Y%m%d-%H:%M:%S")+" "+text+"\n")
            logF.close

def killOldPgm(myPID,pgmToKill):
        global debug, homeDir
        try:
            cmd= "ps -ef | grep "+pgmToKill+" | grep -v grep"
            ret = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()[0]
            lines=ret.split("\n")
            for line in lines:
                if len(line) < 10: continue
                line=line.split()
                pid=int(line[1])
                if pid == int(myPID): continue
                toLog(1, "killing "+pgmToKill)
                os.system("sudo kill -9 "+str(pid))
        except  Exception, e:
            toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))


# ===========================================================================
# Main
# ===========================================================================
global debug, homeDir
homeDir="/home/pi/"
debug=1

try:
        readParams()

        myPID       = str(os.getpid())
        killOldPgm(myPID,"'myoutput.py'")# old old instances of myself if they are still running

        toLog(-1,"myoutput  received text :"+unicode(sys.argv))

        # rest is up to you  the text indgo has send is in sys.argv[1] [2] ....
        if len(sys.argv) >1 :
            text1= sys.argv[1]
            #eg reboot if you send the rebot command
            if text1.find("reboot") > -1 :
                os.system("sudo reboot")
            elif text1.find("gpio 21 high") > -1:
                import RPi.GPIO as GPIO
                GPIO.setmode(GPIO.BCM)
                GPIO.setwarnings(False)
                GPIO.setup(21,GPIO.OUT)
                GPIO.output(21,True)

except  Exception, e:
        toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))

exit(0)

Posted on
Thu Mar 03, 2016 8:55 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: piBEACON: presence monitoring download

v 1.14.1 posted.

fixed:
some internal cosmetics after using PyCharm which pointed out some issues.

added
supports now playing sound files on the rPi through the analog output. You need to have a recent SSD, NOT the radius SSD.
the std SSD 4GB as well as the 8GB support sound.


you need to
- put the mp3 or wave files into ~/Documents/soundFiles/
- send soundfiles to rPis (in menu piBeacon/ Send Config/Restart/Sound to rPi server and click on <send sound files>.)

then use
(a) the menu / Play sound file on rPi/ select the rPi and which player to use and which file to play, then click on <execute>
(B) create action select piBeacon// Play sound file on rPi/ select the rPi and which player to use and which file to play, then execute the action
(C) use a py script in a server script action:
Code: Select all
## first get plugin
plug = indigo.server.getPlugin("com.karlwachs.piBeacon")
if not plug.isEnabled(): return   #### piBeacon  must be enabled, otherwise nothing here works
plug.executeAction("playSoundFile",
   props ={
    "piServerNumber": "0"  ##  rPi server #  0...9
    ,"cmd":         "omxplayer"  #  omxplayer for mp3  or aplay for .wav
    ,"soundFile":   "f1.mp3"  #  file in ~/documents/piBeacon/soundfiles
      }
   )
plug.executeAction("playSoundFile",
   props ={
    "piServerNumber": "0"  ##  rPi server #  0...9
    ,"cmd":         "aplay"  #  omxplayer for mp3  or aplay for .wav
    ,"soundFile":   "bleep_01.wav"  #  file in ~/documents/piBeacon/soundfiles
      }
   )


the reaction time is < 0.5 seconds (after you send the sound files to to the rPi

Karl

Posted on
Fri Mar 04, 2016 1:15 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: piBEACON: presence monitoring download

Posted SSD image download for rPi 3 in first post.

Looks like it all works. YOU DO NEED DIFFERENT SSD IMAGE than with rPi2.

Karl

Posted on
Sat Mar 05, 2016 9:58 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: piBEACON: presence monitoring download

posted v 1.14.3

fixed: input device INP GPIO did not work correctly. (thanks to Wouter)

added
- install of new rPi , download of packages was improved.
- some menue items now include text for rPi type 3 (i.e. when you select pi version)

Karl

Posted on
Sat Mar 05, 2016 11:38 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

piBEACON: presence monitoring download

posted v 1.14.4

fixed:
fingscan interface was complaining even when option was off. fixed

new, changed
1. option to NOT accept new Beacons (in config). when ="do not accept", the rPis will ignore any new iBeacon. (not well tested yet)
2. when starting the programs on the rPi it will check the available disk space, if used is greater than 92% it will not continue; you then must do
ssh pi@xxx ...
sudo raspi-config
and select expand disk (first option and reboot)

if you have done that before and you have 8GB SSD you should not have any problems. With everything configured it takes about 4+GByte

Also the boot might take a bit longer as it checks software versions of installed libs (2. boot will be faster)

Karl

Posted on
Tue Mar 08, 2016 6:37 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: piBEACON: presence monitoring download

posted v 1.15.1

fixed:
1. several smaller issues in menu etc
2. a new rPi could not be configured (bug introduced @ ~1.14.5)
3. did not accept data under some circumstances

thanks to all the testers for finding the bugs


added:
1. for output you now can set a delay of action. i.e. a pin should go from 0 to 1 in 3600 seconds (you can set that in an action, python script or menu)
2. the output value set from menu/action/ py script will be restored at reboot time (option when you set the output value)
3. the TX/RX and the SPI GPIO pins can be used as OUTPUT pins. You have to enable them as output in the rPi device edit. That brings the # of output pins to 16 - should be enough for a sprinkler system
4. management of old iBeacons: delete all old (ignored) or older than some days only
5. print config now has several options to better mange output - just print what you need (active, old, detailed debugging info)
5. option to accept / do not accept new iBeacons. It is set in config. If set to NO. New iBeacons "driving or walking by" will be ignored by the rPis directly.
when you want to add a new beacon you ned dot re enable the option.

This should be a stable version now. I don't want to add any new features for 2 weeks as I will be leaving in a week and would like to iron out any issues that come up.

Karl

Who is online

Users browsing this forum: No registered users and 1 guest