Ejemplo n.º 1
0
def wait_gprs():
    while not cellular.gprs():
        machine.set_idle(True)

        iteration = 0

        led2.value(1)

        while not cellular.is_network_registered():
            delay(60000)
            iteration += 1

            if iteration > 5:
                reset_gsm()
                tm = 1

        led2.value(0)

        try:
            cellular.gprs(get_property('apn'), get_property('login'),
                          get_property('password'))
        except Exception as err:
            print("OS error: {0}".format(err))
            reset_gsm()

        machine.watchdog_reset()
        machine.set_idle(False)
Ejemplo n.º 2
0
def send_rtt_coordinates():
    s = socket.socket()
    s.settimeout(10.0)
    try:
        coords = location.get_coordinates()
        print(get_rtt_string(coords))
        connect_with_timeout(s, get_property('rtt_server'),
                             get_property('rtt_port'), 10)
        s.write(get_rtt_string(coords))
    finally:
        s.close()
Ejemplo n.º 3
0
def auth_user(phone, args):
    print(phone + "" + str(args))
    if len(args) > 0:
        password = get_property("admin_password")

        if password is None or password == "":
            return "Password must be defined before"

        if args[0] == get_property("admin_password"):
            add_admin(phone)
            return "Ok"

    return None
Ejemplo n.º 4
0
def load_model():
	model_filename = os.path.join(settings.APP_STATIC, settings.get_property('model_file'))
	exists = os.path.exists(model_filename)

	if exists:
		print(
			"Loading pre-trained model. If you have updated the training data, please delete " + model_filename + " file.")
		classifier = joblib.load(model_filename)
	else:
		classifier = ChatIntentClassifier(settings.get_property('training_data_file'),
										  settings.get_property('text_field'),
										  settings.get_property('label_field'), settings.get_property('delimiter'))
		save_model(classifier)

	return classifier
Ejemplo n.º 5
0
def prepare_yndx_locator_request():
    gps_data = cellular.agps_station_data()

    mcc = gps_data[0]
    mnc = int(gps_data[1] / 10)
    stations = gps_data[2]

    gsm_cells = [{
        "countrycode": mcc,
        "operatorid": mnc,
        "lac": x[0],
        "cellid": x[1],
        "signal_strength": x[2],
    } for x in stations]

    return {
        "common": {
            "version": "1.0",
            "api_key": get_property('locator_api_key'),
        },
        "gsm_cells": gsm_cells,
        "ip": {
            "address_v4": None
        }
    }
Ejemplo n.º 6
0
def main_iteration():
    global led
    global sms_requested

    led.value(1)
    machine.watchdog_reset()

    try:
        if sms_requested is not None:
            send_coords_by_sms(sms_requested)
            sms_requested = None

        gprs.wait_gprs()
        machine.set_min_freq(machine.PM_SYS_FREQ_39M)
        send_rtt_coordinates()
    except Exception as err:
        print("OS error: {0}".format(err))
        try:
            admins = get_property("admin_numbers")

            if len(admins) > 0:
                cellular.SMS(admins[0], "OS error: {0}".format(err)).send(0)

        except Exception as e:
            pass
    finally:
        machine.watchdog_reset()
        led.value(0)
Ejemplo n.º 7
0
def send_coords_by_sms(number):
    try:
        print("Sending coords")
        coords = location.get_coordinates()
        text = get_property('sms_template').format(lat=coords[0],
                                                   lng=coords[1])
        print("Sending " + text)
        cellular.SMS(number, text).send(0)
    except Exception as err:
        pass
Ejemplo n.º 8
0
def on_call_handler(number):
    global sms_requested
    cellular.on_call(on_call_handler)

    if isinstance(number, str):
        cellular.dial(False)

        phone = '+' + number
        if check_admin_number(phone) and get_property('send_sms_on_call'):
            interrupt = True
            sms_requested = phone
Ejemplo n.º 9
0
def set_password(phone, args):
    if len(args) > 0:
        password = get_property("admin_password")

        #Пароль был задан, значит менять его может только админ
        if password is not None and password != "":
            if not check_admin_number(phone):
                return None

        set_property("admin_password", args[0])
        #TODO save()
        return "Password was set to " + args[0]

    return None
Ejemplo n.º 10
0
def main_loop():
    while (True):

        if charging():
            s.writeRegister("charging effect")
        else:
            si.writeRegister("stop_charging_effect")

        remove_all_sms()
        main_iteration()
        delay(get_property('track_delay_minutes') * 60 * 1000)

        if deep_sleep_allowed and no_move_for_a_long_time():
            send_sms()

            if usb_connected():
                s.writeRegister("sleep effect")

            si.writeRegister("deep_sleep")
Ejemplo n.º 11
0
def get_battery():
    value = adc0.read()
    v = max(get_property('min_bat_adc'), value)
    v = min(get_property('max_bat_adc'), v)
    return (v - get_property('min_bat_adc')) / (
        get_property('max_bat_adc') - get_property('min_bat_adc')) * 100
Ejemplo n.º 12
0
def check_admin_number(phone):
    print("check " + phone + " " + str(get_property("admin_numbers")))
    return phone in get_property("admin_numbers")
Ejemplo n.º 13
0
def add_admin(phone):
    get_property("admin_numbers").append(phone)