Exemple #1
0
def send_sms_normal_msg(recipient, message):

    # sms request paramenter. - sender and apikey,
    # else it will use default set in backend code.
    sms = SendSMS(sender=None, apikey=None)

    # Send sms
    # Enter recipient phone number to whom you want to send sms e.g. 7774005057
    recipient_to = recipient

    # Enter your message
    message = message

    # sms response
    sms_rsp = sms.send_sms(recipient_to, message)
Exemple #2
0
    def __init__(self):
        # Read device settings from config file
        self.sensitivity_threshold = cfg.device_config['sensitivity_threshold']
        self.update_frequency_delay = cfg.device_config[
            'update_frequency_delay']
        self.send_activation_msg = cfg.device_config['send_activation_msg']

        # Initialize the mpu6050
        self.mpu = MPU6050()

        # Initialize Twilio API
        self.sendsms = SendSMS()

        if (self.send_activation_msg):
            self.sendsms.send("Motion detector activated.",
                              self.sendsms.target_phone_number)
Exemple #3
0
def send_sms_activate_account(recipient):

    # sms request paramenter. - sender and apikey,
    # else it will use default set in backend code.
    sms = SendSMS(sender=None, apikey=None)

    # Send sms
    # Enter recipient phone number to whom you want to send sms e.g. 7774005057
    recipient_to = recipient

    # Enter your message
    otp = getotp()
    message = "Test Msg. Dear customer," + otp + "is OTP to activate your CLICK account. OTP are SECRET.DO not disclose it to anyone"
    # sms response
    sms_rsp = sms.send_sms(recipient_to, message)

    #resp = sendSMS(apikey, recipient_to, sender, message)
    print("API Key Response\n", type(sms_rsp))
    print("\n", sms_rsp)
def config_log(directory,
               log_name,
               max_files_uncompressed=1,
               max_level="IMPORTANT",
               compress=True,
               develop=False,
               send_email=False,
               to_emails=None,
               from_email=None,
               pwd=None,
               send_sms=False,
               to_phones=None,
               auth_id=None,
               auth_token=None):
    """
    Configure log using a default pattern and create a new level (important).

    Args:
        directory: folder to save logs;
        log_name: first part of the log name;
        max_files_uncompressed: max number of remaining not compressed files;
        max_level: max level of log;
        compress: indicates if compress the logs or no;
        develop: set output from logging.important to standard ouput (normal print);
        send_email: boolean to activate or not alert by Email on CRITICAL, ERROR or NOTIFY leve.;
        to_emails (needed if send_email is True): list of emails to receive alert;
        from_email (needed if send_email is True): email used to send email alert;
        pwd (needed if send_email is True): from_email password;
        send_sms: boolean to receive or not alert by SMS on CRITICAL, ERROR or NOTIFY level;
        to_phones (needed if send_sms is True): list of phones to receive alert;
        auth_id (needed if send_sms is True): auth id from Plivo;
        auth_token (needed if send_sms is True): auth token from Plivo;
    """
    end_with = '.log'
    directory = _to_path(directory)

    if not path.exists(directory):
        makedirs(directory)

    email_handler = None
    sms_handler = None
    if send_email:
        email_handler = SendEmail(log_name, to_emails, from_email, pwd)

    if send_sms:
        sms_handler = SendSMS(log_name, to_phones, auth_id, auth_token)

    _set_logger(directory, log_name, _get_log_level(max_level), develop,
                email_handler, sms_handler)

    if compress and not develop:
        _clean_up_logs(directory, log_name, end_with, max_files_uncompressed)
Exemple #5
0
    def initUi(self):
        self.ui.btn_close.clicked.connect(self.close)

        self.widgets["call"] = Call(self)
        self.ui.btn_call.clicked.connect(self.widgets["call"].show)

        self.widgets["import_csv"] = ImportCSV(self)
        self.ui.btn_import_csv.clicked.connect(self.widgets["import_csv"].show)

        self.widgets["received_sms"] = ReceivedSMS(self)
        self.ui.btn_show_sms.clicked.connect(self.widgets["received_sms"].show)

        self.widgets["sent_sms"] = SentSMS(self)
        self.ui.btn_sent_sms.clicked.connect(self.widgets["sent_sms"].show)

        self.widgets["send_sms"] = SendSMS(self)
        self.ui.btn_send_sms.clicked.connect(self.widgets["send_sms"].show)

        self.widgets["incoming_call"] = IncomingCall(self)
        self.widgets["incoming_sms"] = IncomingSMS(self)
        self.updateFeedbackSignal.connect(self.updateFeedback)
Exemple #6
0
class Detector():
    def __init__(self):
        # Read device settings from config file
        self.sensitivity_threshold = cfg.device_config['sensitivity_threshold']
        self.update_frequency_delay = cfg.device_config[
            'update_frequency_delay']
        self.send_activation_msg = cfg.device_config['send_activation_msg']

        # Initialize the mpu6050
        self.mpu = MPU6050()

        # Initialize Twilio API
        self.sendsms = SendSMS()

        if (self.send_activation_msg):
            self.sendsms.send("Motion detector activated.",
                              self.sendsms.target_phone_number)

    def watch(self):
        print("Waiting for motion...")

        # Initialize prev_data with the first data sample
        prev_data = self.mpu.read_data()

        # Watch for changes in motion
        while True:
            data = self.mpu.read_data()

            # Check each reading in the data list for changes
            for i in range(5):

                diff = abs(data[i] - prev_data[i])

                # Compare the change with the sensitivity value
                if diff > self.sensitivity_threshold:
                    print("[Motion Detected] Magnitude:", diff)

                    # Get the current time (UTC)
                    self.time = str(datetime.datetime.now())

                    # Format the alert message
                    self.msg = "ALERT: Motion detected at " + self.time[11:19]

                    # Print and send the alert
                    print(self.msg)
                    self.alert(self.msg)

                    # Reset data values
                    data = [0, 0, 0, 0, 0, 0]

                    # Delay to avoid sending multiple alerts at once
                    time.sleep(5)

            # Save data for next read cycle
            prev_data = data

            # Limit the data read cycle speed
            time.sleep(self.update_frequency_delay)

    def alert(self, msg):
        # Send alert message
        self.sendsms.send(self.msg, self.sendsms.target_phone_number)
Exemple #7
0
    # get server ready to handle callback
    server = HTTPServer((ip,port), HttpHandler)

    # twilio client
    client = TwilioRestClient(sid, token)

    # make the call
    log.info("placing call from %s to %s" % (number, to_num))
    msg_params = {"Message[0]": "hello %s, welcome back to the uk" % to_name}
    url="http://twimlets.com/message?" + urllib.urlencode(msg_params),

    call = client.calls.create(to=to_num, 
        from_=number,
        url="http://twimlets.com/message?" + urllib.urlencode(msg_params),
        status_callback="http://%s:%s" % (ip, port),
        timeout=60)
    log.debug(call.sid)

    # handle one request
    log.info("waiting for callback")
    server.handle_request()

    # get status and send message if it got through
    if server.call_status == 'completed':
        # touch a file so we don't run again
        open(run_file, 'a').close()
        log.info("sending sms")
        sms = SendSMS()
        sms.send("%s is back!" % to_name)
Exemple #8
0
class Driver():
	def __init__(self):
		dictfile = open('contacts_info.txt', 'rb')
		self.contacts_dict = pickle.load(dictfile)
		dictfile.close()
		self.smsobj = SendSMS()
		self.mailobj = SendEmail()

	def get_image(self):
		list_of_files = glob.glob('/home/pi/Pictures/server/dark/*')
		latest_file = max(list_of_files, key=os.path.getctime)
		return latest_file

	def detect_digit(self):
		subject = 'Temperature Alert'
		negmsg = 'Unable to detect successfully. Detects: '
		alertmsg = 'Temperature beyond acceptable range. The display reads: '
		img_path = self.get_image()
		tobj = TempDetect(img_path=img_path)
		digits = []

		try:
			# First attempt to detect. cv2.dilate() value = 1
			digits = tobj.final_call(iterval=1)
			digits_str = u'{}{}'.format(*digits)

			# Unable to map to a digit (returns -1)
			if -1 in digits:
				# Second attempt to detect. cv2.dilate() value = 2
				digits = tobj.final_call(iterval=2)
				digits_str = u'{}{}'.format(*digits)

				# Unable to detect second time
				if -1 in digits:
					for key in self.contacts_dict:
						self.mailobj.sendEmail(self.contacts_dict[key]['mailid'], subject, negmsg, img_path)
						self.smsobj.sendSMS(negmsg, self.contacts_dict[key]['mnum'])
					sys.exit()

				#Else, successfully detected (2nd attempt)
			#Else, successfully detected (1st attempt)

		# Unable to detect both the digits correctly
		except IndexError:
			digits = tobj.final_call(iterval=2)
			# Still unable to detect 2nd time (either -1 or misses one digit)
			if -1 in digits or len(digits)<2:
				for key in self.contacts_dict:
					self.mailobj.sendEmail(self.contacts_dict[key]['mailid'], subject, negmsg, img_path)
					if self.contacts_dict[key]['mnum'] != '':
						self.smsobj.sendSMS(negmsg, self.contacts_dict[key]['mnum'])


		digits2 = digits[:2]
		digits_str = ''.join(str(x) for x in digits2)

		for key in self.contacts_dict:
        	if not self.contacts_dict[key]['mint'] < digits_str < self.contacts_dict[key]['maxt']:
	            self.mailobj.sendEmail(self.contacts_dict[key]['mailid'], subject, alertmsg, moved_to)
	            if self.contacts_dict[key]['mnum'] != '':
					self.smsobj.sendSMS(alertmsg, self.contacts_dict[key]['mnum'])

			else:
				# Within the given range. Do nothing.
				pass



mainobj = Driver()
mainobj.detect_digit()
Exemple #9
0
	def __init__(self):
		dictfile = open('contacts_info.txt', 'rb')
		self.contacts_dict = pickle.load(dictfile)
		dictfile.close()
		self.smsobj = SendSMS()
		self.mailobj = SendEmail()