Alarms - fdechaumont/micecraft GitHub Wiki

MiceCraft comes with an Alarm layer to get feedback when a device is not working or is disconnected.

Setting up an alarm that will send you emails

In this example, we create an alarm and we get back to normal after a few seconds

from micecraft.soft.alarm.Alarm import Alarm, AlarmState
from micecraft.soft.mail.Mail import Mail

Mail.config(port, "smtp.provider.com", "[email protected]", "password" ) # setup mail credentials

Alarm.mails = ["[email protected]"] # set who receive the emails.
Alarm.experimentName ="my experiment #012" # your experiment name that will appear in mail title

alarm1 = Alarm( "my alarm for my specific case") # instance of alarm

alarm1.sendAlarmMail( AlarmState.ALARM_ON , "This alarm is a test" )

time.sleep( 5 )

alarm1.sendAlarmMail( AlarmState.ALARM_OFF , "Status is back to normal" )

[!TIP] Note that once the Mail credentials and Alarm mails are set, all the MiceCraft devices will use this channel to send alarms.

[!TIP] setTimeBetweenMailInS let you choose the frequency of mail repetition when an alarm is still on. Default is 10 minutes.

Check if alarm is on

alarm1.isAlarmOn()