Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ulfwin/weatherstation
Browse files Browse the repository at this point in the history
  • Loading branch information
ulfwin committed May 4, 2015
2 parents 2fa5fbe + a20d1d5 commit e6f1e3c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.uwc
*.swp
*.png
*.pyc
17 changes: 17 additions & 0 deletions analysis/analyze.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pylab as pl
import mysqlRetrieve as sql

h = 5
ts = range(0,h*60*60,60)

i = 0.25e-3
C = 2.5
v0 = 3.3
Vb = [ -i*t/C+v0 for t in ts ]

#pl.figure()
#pl.plot(ts,Vb)
#deviceData = pl.array(sql.getAll('Scope_Level'))
deviceData = pl.array(sql.getAll('Battery_Level'))
pl.plot(deviceData[:,0], deviceData[:,1], '.-')
pl.show()
23 changes: 23 additions & 0 deletions analysis/mysqlRetrieve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Script to retrieve and plot mysql data
#
# NOTE! To connect to remote mysql server with ssh tunneling, execute the
# following in a separate command window:
#
# ssh -L 3306:127.0.0.1:3306 <user>@<server>

import MySQLdb

def getAll(table):
conn = MySQLdb.connect(host='127.0.0.1', user='root', passwd='Hejsan12', db='openhab')

with conn:
cur = conn.cursor()
# Find out link between item and table name
cur.execute("SELECT * FROM Items")
tablesInv = cur.fetchall()
# Inverse table and make it a dict
tableDict = {v: k for k, v in tablesInv}
# Get requested table
cur.execute("SELECT * FROM Item%i" %tableDict[table])
return cur.fetchall()

4 changes: 4 additions & 0 deletions lib/ws.weather.station.sblib
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ uuid$ = "e198f87f58b346e7b9a6bedfad46833c"
uuid$ = StrDehexize$(uuid$)
hUuidCustom = BleHandleUuid128(uuid$)
IF hUuidCustom == 0 THEN
if (ENABLE_DEBUG_PRINTS!=0) then
PRINT "\nFailed to create a handle"
endif
ELSE
if (ENABLE_DEBUG_PRINTS!=0) then
PRINT "Handle for custom Uuid is ";integer.h' hUuidCustom;"(";hUuidCustom;")\r"
endif
ENDIF


Expand Down
32 changes: 22 additions & 10 deletions ws.weatherstation.sb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#DEFINE AUTO_STARTUP 3

'//Set this to 0 to disable all debugging messages
#DEFINE ENABLE_DEBUG_PRINTS 1
#DEFINE ENABLE_DEBUG_PRINTS 0

#DEFINE DEVICENAME "Weather"
#DEFINE DEVICENAME_WRITABLE 0
Expand All @@ -51,18 +51,18 @@
#DEFINE MAX_CONN_INTERVAL 4000000
'// Slave latency -- number of conn events that can be missed
'// Effective Conn interval will be (SLAVE_LATENCY+1)*ACTUAL_CONN_INTERVAL
#DEFINE SLAVE_LATENCY 1 //6
#DEFINE SLAVE_LATENCY 6
'// Connection supervisory timeout - max 32 seconds
#DEFINE CONN_SUP_TIMEOUT 1000000 //32000000
#DEFINE CONN_SUP_TIMEOUT 10000000 //32000000
'//DiscoverableMode, set to BLE_DISCOVERABILITY_xxx
#DEFINE DISCOVERY_MODE BLE_DISCOVERABILITY_LIMITED
#DEFINE DISCOVERY_MODE BLE_DISCOVERABILITY_GENERAL
#DEFINE MAX_DEVNAME_CHRS 15
'//Set Appearance advertise 0 to suppress
#DEFINE ADV_APPEARANCE 1
'//Advertise interval (ms)
#DEFINE ADV_INTERVAL_MS 100 //1000
'//Advertise timeout
#DEFINE ADV_TIMEOUT_MS 10000
#DEFINE ADV_INTERVAL_MS 900 //1000
'//Advertise timeout (0 means no timeout)
#DEFINE ADV_TIMEOUT_MS 0 //10000

'//Whitelist Policy in Adverts
#DEFINE ADV_WHITELIST_FILTER_POLICY ADV_FILTERPOLICY_ANY
Expand Down Expand Up @@ -98,7 +98,7 @@

// Time between measurements in milliseconds (60000 is one min)

DIM MEAS_INTERVAL_MS : MEAS_INTERVAL_MS=1000
DIM MEAS_INTERVAL_MS : MEAS_INTERVAL_MS=60000
DIM mv

'//******************************************************************************
Expand All @@ -109,21 +109,33 @@ DIM mv
'// Handler definitions
'//******************************************************************************
#DEFINE MAX_SUPPLY_VOLTAGE_MV 3600
#DEFINE MIN_SUPPLY_VOLTAGE_MV 1600
FUNCTION HandlerTimer0()
mv=ReadPwrSupplyMv()
//PRINT "Supply voltage is ";mv;"mV\r"
DIM battLvl, rc
battLvl=mv*100/MAX_SUPPLY_VOLTAGE_MV
battLvl=(mv-MIN_SUPPLY_VOLTAGE_MV)*100/(MAX_SUPPLY_VOLTAGE_MV-MIN_SUPPLY_VOLTAGE_MV)
rc=SetBattLevel(battLvl)
ENDFUNC 1

FUNCTION HndlrDiscon(BYVAL hConn AS INTEGER, BYVAL nRsn AS INTEGER) AS INTEGER
//Start advertising directly after disconnect
dim rc
rc=StartAds(ADV_IND)
ENDFUNC 1

'//******************************************************************************
'// Equivalent to main() in C
'//******************************************************************************

// Decrease power consumption by disabling UART
UartClose()

ONEVENT EVTMR0 CALL HandlerTimer0
ONEVENT EVDISCON CALL HndlrDiscon


TimerStart(0,1000,1)
TimerStart(0,MEAS_INTERVAL_MS,1)


'//------------------------------------------------------------------------------
Expand Down

0 comments on commit e6f1e3c

Please sign in to comment.