Package: sciler
Developing with scilerClient computer library for S.C.I.L.E.R. systemThis is the library to create devices to work together with the SCILER systemInstallationpip install withpip install scilerUsing this libraryimport lib withfrom sciler.device import Devicecreate a class that extendsDevicein order to do this:implementget_status()which should return a dictionary of the current statusimplementperform_instruction(action)which should return a boolean of whether the instruction can be performed, where action has:instruction: string with the name of the instruction (special casetime)value: any type with a value specific for this instruction (not in case oftimeinstruction )component_id: string with the name of the component for which the instruction is meant (not in case oftimeinstruction ) (can be undefined)idin case oftimeinstruction: string id of timer (generalis the main duration of the escape room)durationin case oftimeinstruction: integer in millisecondsstatein case oftimeinstruction: string of state of timer (stateActive,stateIdle, orstateExpired)implementtest()which returns nothing, this method should do something visible so the operator can test this device works correctlyimplementreset()which returns nothing, this method should make the device return to its starting state so that the escape room can be started againcreate a constructor which calls the constructor ofDevicewithsuper(config, logger)where:config is a dictionary which has keys:id: this is the id of a device. Write it in camelCase, e.g. "controlBoard".host: the IP address of the host for the broker, formatted as a string.portthe port of the host for the broker, formatted as a number.labels: these are the labels to which this device should also subscribe, labels is an array of strings,logger is a function(date, level, message) in which an own logger is implemented wheredateis an Date objectlevelis one of the following strings: 'debug', 'info', 'warn', 'error', 'fatal'messageis a custom string containing more informationit should also add event listeners to GPIO for all input components.implementmain()which should callstart(loop, stop)with an optional event loop and ending function.Now in your class which implementsDeviceyou can call:log(level, message)which logs using the logger provided inDevicewhere level one of the following strings: 'debug', 'info', 'warn', 'error', 'fatal' and message custom string containing more informationstatus_changed()which can be called to signal toDevicethat the status is changed, this will send a new status to SCILERTo now start the systeminitialize the device in your main program and calldevice.main()Exampleimportosfromsciler.deviceimportDeviceclassDisplay(Device):def__init__(self):two_up=os.path.abspath(os.path.join(__file__,".."))rel_path="display_config.json"abs_file_path=os.path.join(two_up,rel_path)abs_file_path=os.path.abspath(os.path.realpath(abs_file_path))config=open(file=abs_file_path)super().__init__(config)self.hint=""defget_status(self):return{"hint":self.hint}defperform_instruction(self,action):instruction=action.get("instruction")ifinstruction=="hint":self.show_hint(action)else:returnFalse,actionreturnTrue,Nonedeftest(self):self.hint="test"print(self.hint)self.status_changed()defshow_hint(self,data):self.hint=data.get("value")print(self.hint)self.status_changed()defreset(self):self.hint=""self.status_changed()defmain(self):self.start()if__name__=="__main__":device=Display()device.main()wheredisplay_config.jsonis{"id":"display","description":"Display can print hints","host":"192.168.178.82","labels":["hint"],"port":1883}example ofmain()with loop and stop:defloop(self):previous=self.get_sliders_analog_reading()whileTrue:positions=self.get_sliders_analog_reading()ifprevious!=positions:self.status_changed()previous=positionsdefmain(self):self.setup_events()self.start(loop=self.loop,stop=GPIO.cleanup)To run on bootuse tool like supervisord:runsudo apt-get install supervisorrunsudo nano /etc/supervisor/conf.d/<devicename>.confand save:[program:devicename]
directory=/home/pi
command=python3 devicename.py
user=pi
group_name=pi
stdout_logfile=/home/pi/sciler_logs/logs_devicename.txt
redirect_stderr=true
autostart=true
autorestart=truerunsudo supervisorctl rereadandsudo supervisorctl updaterunsudo supervisorctlto check statusLicenseThis library is licensed with GNU GPL v3, seeLICENSE.md.