Beispiel #1
0
#!/usr/bin/python

__author__ = 'Bernd Gewehr'

import time

import lib_mqtt as MQTT
from  lib_hmc5883l import  hmc5883l
import os

DEBUG = False

if __name__ == '__main__':
    os.nice(10)
    try:
        MQTT.init()
        while True:
            time.sleep(0.1)
            compass = hmc5883l(gauss = 4.7, declination = (1,36))
            if DEBUG:
                print ("\rHeading: " + str(compass.heading()))
            MQTT.mqttc.publish("/RPiMower/Compass", str(compass.heading()))

    # interrupt
    except KeyboardInterrupt:
        print("Programm interrupted")
        MQTT.cleanup()
        sys.exit(2)


def getVehicleDetails(s, url_base):
    print(CarNetPost(s, url_base, '/-/vehicle-info/get-vehicle-details'))
    return 0


if __name__ == "__main__":
    s = requests.Session()
    url = CarNetLogin(s, CARNET_USERNAME, CARNET_PASSWORD)
    if url == '':
        print("Failed to login")
        sys.exit()

    # Init MQTT connections
    MQTT.init()
    print 'MQTT initiated'
    #MQTT.mqttc.on_message = on_message
    #MQTT.mqttc.subscribe(MQTT_TOPIC_IN, qos=MQTT_QOS)

    if len(sys.argv) != 2:
        print "Need at least one argument."
        sys.exit()
    else:
        if (sys.argv[1] == "retrieveCarNetInfo"):
            retrieveCarNetInfo(s, url)
        if (sys.argv[1] == "startCharge"):
            startCharge(s, url)
        elif (sys.argv[1] == "stopCharge"):
            stopCharge(s, url)
        elif (sys.argv[1] == "startClimat"):