Skip to content

Commit

Permalink
Check if another instance is running before start
Browse files Browse the repository at this point in the history
  • Loading branch information
enesbcs committed Feb 24, 2021
1 parent 746e8fd commit 6995562
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 16 deletions.
4 changes: 4 additions & 0 deletions RPIEasy.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def hardwareInit():
if rpieGlobals.osinuse=="linux":
import linux_os as OS
import linux_network as Network
if OS.isAlreadyRunning()>1:
time.sleep(1)
print("\nAn RPIEasy is already running! Close that first!")
sys.exit(0)
Settings.NetMan = Network.NetworkManager()
if len(OS.getsounddevs())>0:
Settings.SoundSystem["usable"]=True
Expand Down
4 changes: 2 additions & 2 deletions _C001_DomoHTTP.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self,controllerindex):
self.usesAccount = True
self.usesPassword = True
self.authmode = 0

def webform_load(self):
try:
am = self.authmode
Expand All @@ -36,7 +36,7 @@ def webform_load(self):
optionvalues = [0,1,2]
webserver.addFormSelector("Mode","c001_mode",len(optionvalues),options,optionvalues,None,int(am))
return True

def webform_save(self,params):
try:
self.authmode = int(webserver.arg("c001_mode",params))
Expand Down
4 changes: 3 additions & 1 deletion _C004_ThingSpeak.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ def controller_init(self,enablecontroller=None):
if self.controllerpassword!="" and self.controllerip!="" and self.controllerip!="0.0.0.0":
self.initialized = True
return self.initialized

def senddata(self,idx,sensortype,value,userssi=-1,usebattery=-1,tasknum=-1,changedvalue=-1):
if tasknum is None:
return False
if self.enabled and self.initialized:
if tasknum!=-1:
if time.time()-self.lastsend<self.defaultdelay:
Expand Down
9 changes: 7 additions & 2 deletions _C008_GenHTTP.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@ def webform_save(self,params): # process settings post reply
return True

def senddata(self,idx,sensortype,value,userssi=-1,usebattery=-1,tasknum=-1,changedvalue=-1): # called by plugin
if tasknum is None:
return False
if tasknum!=-1 and self.enabled:
if tasknum<len(Settings.Tasks):
if Settings.Tasks[tasknum] != False:
procarr = []
try:
hn = str(urllib.parse.quote(str(Settings.Tasks[tasknum].gettaskname())))
templatestra = self.templatestr.replace('%tskname%',hn)
templatestra = templatestra.replace('%id%',str(tasknum+1))
procarr = []
for u in range(Settings.Tasks[tasknum].valuecount):
vn = str(Settings.Tasks[tasknum].valuenames[u]).strip()
if vn!="":
Expand All @@ -67,7 +70,9 @@ def senddata(self,idx,sensortype,value,userssi=-1,usebattery=-1,tasknum=-1,chang
t.daemon = True
procarr.append(t)
t.start()
if len(procarr)>0:
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,e)
if len(procarr)>0:
for process in procarr:
process.join()

Expand Down
2 changes: 2 additions & 0 deletions _C009_FHEM.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def getIP(self):
return self.ip

def senddata(self,idx,sensortype,value,userssi=-1,usebattery=-1,tasknum=-1,changedvalue=-1):
if tasknum is None:
return False
if self.enabled:
if tasknum!=-1:
jdata = {}
Expand Down
2 changes: 2 additions & 0 deletions _C010_GenUDP.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def udpsender(self,data):
print(e)

def senddata(self,idx,sensortype,value,userssi=-1,usebattery=-1,tasknum=-1,changedvalue=-1): # called by plugin
if tasknum is None:
return False
if tasknum!=-1 and self.enabled:
if tasknum<len(Settings.Tasks):
if Settings.Tasks[tasknum] != False:
Expand Down
2 changes: 2 additions & 0 deletions _C013_ESPEasyP2P.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ def udpsender(self,unitno,data,retrynum=1):
time.sleep(0.1)

def senddata(self,idx,sensortype,value,userssi=-1,usebattery=-1,tasknum=-1,changedvalue=-1): # called by plugin
if tasknum is None:
return False
if tasknum!=-1 and self.enabled:
if tasknum<len(Settings.Tasks):
if Settings.Tasks[tasknum] != False:
Expand Down
2 changes: 2 additions & 0 deletions _C014_GenMQTT.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ def on_message(self, msg):

def senddata(self,idx,sensortype,value,userssi=-1,usebattery=-1,tasknum=-1,changedvalue=-1):
if self.enabled:
if tasknum is None:
return False
success = False
if self.isconnected(False):
if self.useJSON:
Expand Down
2 changes: 2 additions & 0 deletions _C015_Blynk.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def on_message(self,vpin,msg):

def senddata(self,idx,sensortype,value,userssi=-1,usebattery=-1,tasknum=-1,changedvalue=-1):
if self.enabled and BLYNK.blynkconnected:
if tasknum is None:
return False
if tasknum!=-1:
if changedvalue==-1:
for u in range(Settings.Tasks[tasknum].valuecount):
Expand Down
2 changes: 1 addition & 1 deletion _C016_DBStore.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def webform_save(self,params):
return True

def senddata(self,idx,sensortype,value,userssi=-1,usebattery=-1,tasknum=-1,changedvalue=-1):
if self.enabled:
if self.enabled and tasknum is not None:
sqlstr = "insert into easysensor (time,unit,nodename,taskname,sensortype"
sqlstr2 = ") values ('"+ str(datetime.datetime.now()) +"',"+str(Settings.Settings["Unit"])+",'"+str(Settings.Settings["Name"])+"','"+str(Settings.Tasks[tasknum].gettaskname())+"',"+str(sensortype)
vcount = 4
Expand Down
2 changes: 2 additions & 0 deletions _C020_LoraDirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ def pkt_receiver(self,payload,rssi):

def senddata(self,idx,sensortype,value,userssi=-1,usebattery=-1,tasknum=-1,changedvalue=-1): # called by plugin
if self.enabled and self.initialized and self.enablesend:
if tasknum is None:
return False
if int(idx)>0:
if Settings.Tasks[tasknum].remotefeed == False: # do not republish received values
dp2 = p2pbuffer.data_packet()
Expand Down
2 changes: 2 additions & 0 deletions _C021_BLEDirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ def pkt_receiver(self,payload): # processing incoming packets
def senddata(self,idx,sensortype,value,userssi=-1,usebattery=-1,tasknum=-1,changedvalue=-1): # called by plugin
if self.enabled and self.initialized:
# print(idx,value) # debug
if tasknum is None:
return False
if int(idx)>0:
if Settings.Tasks[tasknum].remotefeed==False or Settings.Tasks[tasknum].remotefeed==-1: # do not republish received values
dp2 = p2pbuffer.data_packet()
Expand Down
2 changes: 1 addition & 1 deletion _C022_ESPNow.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def pkt_receiver(self,payload):


def senddata(self,idx,sensortype,value,userssi=-1,usebattery=-1,tasknum=-1,changedvalue=-1): # called by plugin
if self.enabled and self.initialized and self.enablesend:
if self.enabled and self.initialized and self.enablesend and tasknum is not None:
if int(idx)>0:
if int(Settings.Tasks[tasknum].remotefeed) < 1: # do not republish received values
dp2 = p2pbuffer.data_packet()
Expand Down
2 changes: 1 addition & 1 deletion _C023_IFTTT.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def controller_init(self,enablecontroller=None):
return self.initialized

def senddata(self,idx,sensortype,value,userssi=-1,usebattery=-1,tasknum=-1,changedvalue=-1):
if self.enabled and self.initialized:
if self.enabled and self.initialized and tasknum is not None:
if tasknum!=-1:
jdata = {}
jdata['key'] = self.controllerpassword
Expand Down
9 changes: 7 additions & 2 deletions _P033_Dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ def __init__(self,taskindex): # general init
self.formulaoption = True

def plugin_receivedata(self,data):
if data is None:
return False
if (len(data)>0):
for x in range(len(data)):
if data[x] != -9999:
self.set_value(x+1,data[x],False)
try:
if int(data[x]) != -9999:
self.set_value(x+1,data[x],False)
except:
pass
# print("Data received:",data)#debug

def getvaluecount(self):
Expand Down
14 changes: 11 additions & 3 deletions linux_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ def checkRockPI():
return rpi

def getRockPIVer():
hwarr = {
hwarr = {
"name": "Unknown model",
"pins": "0",
"ver" : "0.0"}
Expand All @@ -893,11 +893,11 @@ def getRockPIVer():
hwarr["name"] = ta[0]
hwarr["pins"] = ta[1]
hwarr["ver"] = ta[2]
return hwarr
return hwarr
except Exception as e:
notrock = True
try:
output = os.popen('mraa-gpio version')
output = os.popen('mraa-gpio version')
for line in output:
if 'rock' in line.lower():
tf = line.find(" on")
Expand All @@ -910,3 +910,11 @@ def getRockPIVer():
hwarr["name"] = "Unknown Rockchip"
hwarr["pins"] = "X"
return hwarr

def isAlreadyRunning():
output = os.popen('ps -aux | grep RPIEasy').read()
try:
occ = int(output.count("RPIEasy.py"))
except:
occ = 0
return occ
4 changes: 2 additions & 2 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ def plugin_write(self,cmd): # deal with command from outside
def plugin_receivedata(self,data): # data arrived from controller
result = False
return result

def plugin_senddata(self,puserssi=-1,pusebattery=-1,pchangedvalue=-1):
for x in range(rpieGlobals.CONTROLLER_MAX):
if self.senddataenabled[x]:
try:
if type(self.controllercb[x])==type(self.plugin_senddata):
if (len(self.controllercb)>x) and (type(self.controllercb[x])==type(self.plugin_senddata)):
self.controllercb[x](self.controlleridx[x],self.vtype,self.uservar,userssi=puserssi,usebattery=pusebattery,tasknum=self.taskindex,changedvalue=pchangedvalue)
except Exception as e:
# print(x,len(self.controllercb),self.controllercb,self.controlleridx)
Expand Down
2 changes: 1 addition & 1 deletion rpieGlobals.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Copyright (C) 2018-2020 by Alexander Nagy - https://bitekmindenhol.blog.hu/
#
PROGNAME = "RPIEasy"
BUILD = 21053
BUILD = 21055
PROGVER = str(BUILD)[:1]+"."+str(BUILD)[1:2]+"."+str(BUILD)[2:]

gpMenu = []
Expand Down
9 changes: 9 additions & 0 deletions win_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,12 @@ def setvolume(volume): # volume in percentage
def detectNM():
nm = False
return nm

def checkRockPi():
return False

def getRockPiVer():
return {"name":"","pins":"","ver":"0.0"}

def isAlreadyRunning():
return 0

0 comments on commit 6995562

Please sign in to comment.