-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyXY SM700 Exosite Demo.py
executable file
·109 lines (93 loc) · 4.61 KB
/
pyXY SM700 Exosite Demo.py
1
# Copyright (C) 2012 Exosite, LLC.# Subject to your agreement of the disclaimer set forth below, permission is given by Exosite, LLC ("Exosite") to you to freely modify, redistribute or include this SNAPpy code in any program. The purpose of this code is to help you understand and learn about SNAPpy and Exosite by code examples.# BY USING ALL OR ANY PORTION OF THIS SNAPPY CODE, YOU ACCEPT AND AGREE TO THE BELOW DISCLAIMER. If you do not accept or agree to the below disclaimer, then you may not use, modify, or distribute this SNAPpy code.# THE CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES WILL SYNAPSE BE LIABLE TO YOU, OR ANY OTHER PERSON OR ENTITY, FOR ANY LOSS OF USE, REVENUE OR PROFIT, LOST OR DAMAGED DATA, OR OTHER COMMERCIAL OR ECONOMIC LOSS OR FOR ANY DAMAGES WHATSOEVER RELATED TO YOUR USE OR RELIANCE UPON THE SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES OR IF SUCH DAMAGES ARE FORESEEABLE. THIS DISCLAIMER OF WARRANTY AND LIABILITY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.### Exosite demo for pyXY Synapse dev board# Module Platform: SM700## Sends/Reads data to Exosite via Synapse Portal IDE# Use in conjunction with Synapse Portal IDE script#from synapse.switchboard import *from synapse.nvparams import *from synapse.platforms import *from synapse.hexSupport import *CIK = ''NV_EXOSITE_CIK = 154portalAddr = '\x00\x00\x01' # hard-coded address for Synapse Portal IDE on your PCblinkled = 10 #default milliseconds for LED pulsefirstTime = TruepollCount = 0#Analog Pins:AD0_GPIO = GPIO_30AD0 = 0AD1_GPIO = GPIO_31AD1 = 1AD2_GPIO = GPIO_32AD2 = 2AD3_GPIO = GPIO_33AD3 = 3AD4_GPIO = GPIO_34AD4 = 4AD5_GPIO = GPIO_35AD5 = 5AD6_GPIO = GPIO_36AD6 = 6#GPIO Pins:TMR2 = GPIO_10brdStatusLEDPin = TMR2@setHook(HOOK_STARTUP)def startup(): global CIK,blinkled,gwaddr gwaddr = portalAddr # Do we have a CIK? if(loadNvParam(NV_EXOSITE_CIK) != None and loadNvParam(NV_EXOSITE_CIK) != "" ): CIK = loadNvParam(NV_EXOSITE_CIK) if CIK == '': portal_debug_msg = "** Node with no CIK is booting, it needs have CIK programmed or be provisioned" else: portal_debug_msg = "** Node with CIK " + CIK + " is booting" rpc(portalAddr,"logEvent",portal_debug_msg) #register to Synapse Portal app log # Proto board Board LEDs initialization setPinDir(brdStatusLEDPin, True) if CIK != '': rpc(gwaddr, 'exosite_write', CIK, 'status','restart')@setHook(HOOK_100MS)def poll100ms(msTick): global lqSum,lqSumPts,CIK,pollCount,ping,blinkled,firstTime pollCount += 1 lqSum += getLq() # get the link Quality every 100ms lqSumPts += 1 if CIK != '': if (pollCount % 20) == 0: pulsePin(brdStatusLEDPin,blinkled,True) pulsePin(brdStatusLEDPin,blinkled,True) # Send signal value every 1 minute if (pollCount % 200) == 0: signal = (lqSum / lqSumPts) # calc the avg to send # # NOTE: The value is positive but represents -dBm # On the Exosite Portal, the data source has a preprocess to # multiply by -1 as raw data comes in # rpc(portalAddr, "logData", 'Signal', signal, 100) #View in Synapse Portal (debugging) if (signal > 0): #mcastRpc(MCAST_GROUP, MCAST_HOPS, 'exosite_write', CIK, 'signal',signal) rpc(gwaddr,'exosite_write',CIK, 'signal',signal) source = getNetId() rpc(gwaddr,'exosite_read',CIK, 'signal',source) pass lqSum = 0 # reset the link quality sum after updating lqSumPts = 0 # reset the link quality number of points after updating else: if (pollCount % 2) == 0: pulsePin(brdStatusLEDPin,blinkled,True)def getPercentLq(): """Calculate the Link Quality as a percentage""" maxDbm = 18 minDbm = 95 # Use the built-in function to get the current LQ reading percent = 100 - ((getLq() - maxDbm) * 100) / (minDbm - maxDbm) return percent