Ejemplo n.º 1
0
def send_cloud():
    global state

    DEFAULT_CONFIG_PATH = 'config2.json'

    with open(DEFAULT_CONFIG_PATH, 'r') as config_file:
        config = json.load(config_file)

    # Configure Oauth2 access token for the client application
    artikcloud.configuration = artikcloud.Configuration()
    artikcloud.configuration.access_token = config['device_token']

    # Create an instance of the API Class
    api_instance = artikcloud.MessagesApi()
    device_message = {}
    device_message['State1'] = state[0]
    device_message['State2'] = state[1]
    device_sdid = config['device_id']
    ts = None

    # Construct a Message Object for request
    data = artikcloud.Message(device_message, device_sdid, ts)

    try:
        api_response = api_instance.send_message(data)  # Send Message
    except ApiException as e:
        pprint("Exception when calling MessagesApi->send_message: %s\n" % e)
    print "Send to cloud success"
Ejemplo n.º 2
0
def main(argv):

    DEFAULT_CONFIG_PATH = 'config.json'

    with open(DEFAULT_CONFIG_PATH, 'r') as config_file:
        config = json.load(config_file)['metroBeaconSensor']
    print(config)

    # Configure Oauth2 access_token for the client application.  Here we have used
    # the device token for the configuration
    artikcloud.configuration = artikcloud.Configuration()
    artikcloud.configuration.access_token = config['deviceToken']

    # We create an instance of the Message API class which provides
    # the send_message() and get_last_normalized_messages() api call
    # for our example
    api_instance = artikcloud.MessagesApi()

    # parameters for our request
    sdids = config[
        'deviceId']  # str | Comma separated list of source device IDs (minimum: 1). (required)
    #count = 10 # int | Number of items to return per query. (optional)
    #field_presence = None # str | String representing a field from the specified device ID. (optional)

    try:
        # Debug Print oauth settings
        pprint(artikcloud.configuration.auth_settings())

        # Get Last Normalized Message
        api_response = api_instance.get_last_normalized_messages(sdids=sdids)
        pprint(api_response)
    except ApiException as e:
        print "Exception when calling MessagesApi->get_last_normalized_messages: %s\n" % e
Ejemplo n.º 3
0
def send_data_IOT_cloud(p_rain):
    try:
        # SDK reference for more details
        # https://github.com/artikcloud/artikcloud-python
        # Configure Oauth2 access_token for the client application.  Here we have used
        # the device token for the configuration
        artikcloud.configuration = artikcloud.Configuration()
        artikcloud.configuration.access_token = config['domohome_rain'][
            'device_token']
        # We create an instance of the Message API class which provides
        # the send_message() and get_last_normalized_messages() api call
        # for our example
        api_instance = artikcloud.MessagesApi()
        # Device_message - data that is sent to your device
        device_message = {}
        device_message['rain'] = p_rain
        # Set the 'device id' - value from your config.json file
        device_sdid = config['domohome_wind']['device_id']
        # set your custom timestamp
        ts = None
        # Construct a Message object for your request
        data = artikcloud.Message(device_message, device_sdid, ts)
        #print(data)
        #pprint(artikcloud.configuration.auth_settings())
        # Send Message
        api_response = api_instance.send_message(data)
        pprint(api_response)
    except ApiException as e:
        pprint("Exception when calling MessagesApi->send_message: %s\n" % e)
        logger.error("Exception when calling MessagesApi->send_message: %s\n" %
                     e)
Ejemplo n.º 4
0
def main(argv):
    DEFAULT_CONFIG_PATH = 'config.json'

    with open(DEFAULT_CONFIG_PATH, 'r') as config_file:
        config = json.load(config_file)
#       print(config)

# Configure Oauth2 access token for the client application
    artikcloud.configuration = artikcloud.Configuration()
    artikcloud.configuration.access_token = config['device_token']

    # File In/Out
    ff = open('send_data.txt', 'r')
    adcVal = float(ff.read())
    print "[  SEND  ] ADC value is", str(adcVal)
    print('  ')

    # Create an instance of the API Class
    api_instance = artikcloud.MessagesApi()
    device_message = {}
    device_message['TEMP'] = adcVal
    device_sdid = config['device_id']
    ts = None  # timestamp

    # Construct a Message Object for request
    data = artikcloud.Message(device_message, device_sdid, ts)

    try:
        #               pprint(artikcloud.configuration.auth_settings()) # Debug Print
        api_response = api_instance.send_message(data)  # Send Message


#               pprint(api_response)
    except ApiException as e:
        pprint("Exception when calling MessagesApi->send_message: %s\n" % e)
Ejemplo n.º 5
0
    def initSubcriber(self):
        with open("config.json", 'r') as config_file:
            self.config = json.load(config_file)['Temp Sensor']

        artikcloud.configuration = artikcloud.Configuration();
        artikcloud.configuration.access_token = self.config['deviceToken']

        self.api_instance = artikcloud.MessagesApi()
        self.sdids = self.config['deviceId']
Ejemplo n.º 6
0
def main(argv):
    DEFAULT_CONFIG_PATH = 'config.json'

    with open(DEFAULT_CONFIG_PATH, 'r') as config_file:
        config = json.load(config_file)


#       print(config)

    artikcloud.configuration = artikcloud.Configuration()
    artikcloud.configuration.access_token = config['device_token']

    # create an instance of the API class
    api_instance = artikcloud.MessagesApi()
    count = 1
    start_date = int(time.time() * 1000) - 86400000  # 24 hours ago
    end_date = int(time.time() * 1000)  # current
    order = 'desc'

    try:
        # Get Normalized Actions
        api_response = api_instance.get_normalized_actions(
            count=count, end_date=end_date, start_date=start_date, order=order)
        #               pprint(api_response)
        actionName = api_response.data[0].data.actions[0].name
        if actionName == "RED":
            pinVAL = open(red_path_val, "wb", 0)
            pinVAL.write(str(1))
            pinVAL.close()
            pinVAL = open(green_path_val, "wb", 0)
            pinVAL.write(str(0))
            pinVAL.close()

            #                       ff = open('led_state.txt','w')
            #           ff.write('1')
            #           ff.close()
            print('[RECEIVED] RED LED On')
        else:
            pinVAL = open(green_path_val, "wb", 0)
            pinVAL.write(str(1))
            pinVAL.close()
            pinVAL = open(red_path_val, "wb", 0)
            pinVAL.write(str(0))
            pinVAL.close()
            #                       ff = open('led_state.txt','w')
            #           ff.write('0')
            #           ff.close()
            print('[RECEIVED] GREEN LED ON')

    except ApiException as e:
        print(
            "Exception when calling MessagesApi->get_normalized_actions: %s\n"
            % e)
Ejemplo n.º 7
0
def main(argv):
    
  
	DEFAULT_CONFIG_PATH = 'config.json'
	
	with open(DEFAULT_CONFIG_PATH, 'r') as config_file:
			config = json.load(config_file)
	print(config)

	# Configure Oauth2 access token for the client application
	artikcloud.configuration = artikcloud.Configuration();
	artikcloud.configuration.access_token = config['device_token']

	# Read ADC Pin (Temperature sensor)
	adcPATH = "/sys/devices/platform/c0000000.soc/c0053000.adc/iio:device0/in_voltage0_raw"
	target = open(adcPATH, 'r')
	adcVal = float(target.read(8))
	voltage = 0.439453125 * adcVal * 2
	temper = -36.875 + 217.75 * voltage/5000
	del dla[0]
	dla.append(temper)
	k=np.array(dla).reshape(-1,1)
	model.fit(tempindex,k)
	y=model.predict(7)
    
	target.close();
	print('  ')
	print ("Temper is", str(temper))
	print('  ')

	print('  ')
	print ("Predict Temper is", str(y))
	print('  ')

	# Create an instance of the API Class
	api_instance = artikcloud.MessagesApi()
	device_message = {}
	device_message['currentTemp'] = temper
	device_message['targetTemp'] = y[0][0]
	device_sdid = config['device_id']
	ts = None                         

	# Construct a Message Object for request
	data = artikcloud.Message(device_message, device_sdid, ts)

	try:
		pprint(artikcloud.configuration.auth_settings()) # Debug Print
		api_response = api_instance.send_message(data) # Send Message
		pprint(api_response)
	except ApiException as e:
		pprint("Exception when calling MessagesApi->send_message: %s\n" % e)
Ejemplo n.º 8
0
def main(argv):

    DEFAULT_CONFIG_PATH = 'config.json'

    with open(DEFAULT_CONFIG_PATH, 'r') as config_file:
        config = json.load(config_file)['metroBeaconSensor']
    print(config)

    # Configure Oauth2 access_token for the client application.  Here we have used
    # the device token for the configuration
    artikcloud.configuration = artikcloud.Configuration()
    artikcloud.configuration.access_token = config['deviceToken']

    # We create an instance of the Message API class which provides
    # the send_message() and get_last_normalized_messages() api call
    # for our example
    api_instance = artikcloud.MessagesApi()

    # Device_message - data that is sent to your device
    device_message = {}

    # We send random values to the 'temp' field for this FireSensor.
    # Let's send a random value between 0 and 200 for this demo.
    device_message['train1'] = random.randrange(0, 200)

    # Set the 'device id' - value from your config.json file
    device_sdid = config['deviceId']

    # set your custom timestamp
    ts = time.time()

    # Construct a Message object for your request
    data = artikcloud.Message(device_message, device_sdid, ts)

    try:
        # Debug Print oauth settings
        pprint(artikcloud.configuration.auth_settings())

        # Send Message
        api_response = api_instance.send_message(data)
        pprint(api_response)
    except ApiException as e:
        print "Exception when calling MessagesApi->send_message: %s\n" % e
Ejemplo n.º 9
0
def main(argv):

    DEFAULT_CONFIG_PATH = 'config.json'

    with open(DEFAULT_CONFIG_PATH, 'r') as config_file:
        config = json.load(config_file)['metroBeaconSensor']
    print(config)

    artikcloud.configuration = artikcloud.Configuration()
    artikcloud.configuration.access_token = config['deviceToken']

    api_instance = artikcloud.MessagesApi()

    sdids = config['band_id']
    try:
        pprint(artikcloud.configuration.auth_settings())
        api_response = api_instance.get_last_normalized_messages(sdids=sdids)
        pprint(api_response)
    except ApiException as e:
        print "Exception when calling MessagesApi->get_last_normalized_messages: %s\n" % e
def main(argv):
    sensor = Adafruit_DHT.DHT22
    pin = 4

    humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)

    DEFAULT_CONFIG_PATH = 'config.json'

    with open(DEFAULT_CONFIG_PATH, 'r') as config_file:
        config = json.load(config_file)
    print(config)

    artikcloud.configuration = artikcloud.Configuration()
    artikcloud.configuration.access_token = config['device_token']

    api_instance = artikcloud.MessagesApi()

    device_message = {}

    if humidity is not None and temperature is not None:
        try:
            device_message['temp'] = temperature
            device_message['humidity'] = humidity
            device_sdid = config['device_id']
            ts = None
            data = artikcloud.Message(device_message, device_sdid, ts)

            # Debug Print oauth settings
            pprint(artikcloud.configuration.auth_settings())

            # Send Message
            api_response = api_instance.send_message(data)
            pprint(api_response)
        except ApiException as e:
            pprint("Exception when calling MessagesApi->send_message: %s\n" %
                   e)
        print('Temp={0:0.1f}*  Humidity={1:0.1f}%'.format(
            temperature, humidity))
    else:
        print('Failed to get reading. Try again!')
        sys.exit(1)
Ejemplo n.º 11
0
    def test_send_actions(self):
        """
        Test case for send_actions

        Send Actions
        """
        ddid = self.properties['device4.id']

        configuration = artikcloud.Configuration();
        configuration.access_token = self.properties['device4.token']
        api = MessagesApi()

        action = Action()
        action.name = 'setVolume'
        action.parameters = {'volume': 5}

        action_array = ActionArray()
        action_array.actions = [ action ]

        actions = Actions()
        actions.ddid = ddid
        actions.ts = int(round(time.time() * 1000))
        actions.data = action_array

        mid = api.send_actions(actions).data.mid

        time.sleep(2)

        envelope = api.get_normalized_actions(mid=mid)
        self.assertEqual(1, envelope.size)

        normalized = envelope.data[0]
        action_rx = normalized.data.actions[0]

        self.assertEqual('setVolume', action_rx.name)
        volume = action_rx.parameters['volume']

        self.assertIsNotNone(volume, 'Volume should not be None')
        self.assertEqual(5.0, volume)
Ejemplo n.º 12
0
def main(argv):
  DEFAULT_CONFIG_PATH = 'config.json'
  global TRACE
  global recStart
  global recentFull
  global fullTime
  global manualWaterOut
  global recordTime
  
  TRACE = sys.argv[1]  # for Debug
	
  with open(DEFAULT_CONFIG_PATH, 'r') as config_file:
    config = json.load(config_file)  # dict instance of config.json

  # Configure Oauth2 access token for the client application 
  artikcloud.configuration = artikcloud.Configuration()
  artikcloud.configuration.access_token = config['device_token']
  
  # Read ADC Pin (water level sensor)
  water_level = analogRead(wlPin)
  debugprint('water level is {0}'.format(water_level))
  
  # create an instance of the API class 
  api_instance = artikcloud.MessagesApi()
  
  # for getting actions
  count = 1		
  start_date = int(time.time()*1000) - 86400000
  end_date = int(time.time()*1000)
  order = 'desc'

  # Get Normalized Actions
  try:
    api_actions = api_instance.get_normalized_actions(count=count, end_date = end_date, start_date = start_date, order = order)
    Mode = str(api_actions.data[0].data.actions[0].parameters[u'Code'])
  debugprint(Mode)
  except ApiException as e:
    print("Exception when calling MessagesApi->get_normalized_actions: %s\n" % e)
    def setUp(self):
        configuration = artikcloud.Configuration()
        configuration.access_token = self.properties['user1.token']

        self.api = UsersApi()
        self.user_id = self.api.get_self().data.id
Ejemplo n.º 14
0
import serial
import string
import time
import subprocess
import artikcloud
from artikcloud.rest import ApiException
from pprint import pprint


#cloud
device_token = "256d57fbb481455abda36ed8563b59d4"
device_id = "34e6d7c9bc754fd294f96bae4a786ba9"

artikcloud.configuration = artikcloud.Configuration();
artikcloud.configuration.access_token = device_token

gauges2 = serial.Serial()
gauges2.port = '/dev/rfcomm1'
gauges2.baudrate = 9600
gauges2.parity = 'N'
gauges2.writeTimeourt = 0
gauges2.timeout = 3
gauges2.open()

print("Connected to " + gauges2.portstr)

while True:
	weight = 0
	try:
		get_str = gauges2.readline()
		get_str.replace("\n","")
Ejemplo n.º 15
0
def main(argv):

    table_name = 'envtable'
    dt_col = 'date_time'
    temp_col = 'temp'
    humidity_col = 'humidity'
    air_pollution_col = 'air_pollution'

    try:
        # Create a database
        db = sqlite3.connect('data/envdb')

        # Get a cursor object
        cursor = db.cursor()
        cursor.execute('CREATE TABLE IF NOT EXISTS \
                      {tn} ({dt} datetime, {t} REAL, {h} REAL, {a} REAL)'  \
                        .format(tn=table_name, dt=dt_col, t=temp_col, h=humidity_col, a=air_pollution_col))
        db.commit()
    except Exception as e:
        db.rollback()
        print('Failed to open or create table')
        raise e
    #finally:
    #db.close()

    # initialize GPIO
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BCM)
    GPIO.cleanup()
    # read data using pin 14

    # Initialize the ADS1115 ADC (16-bit) instance
    adc = Adafruit_ADS1x15.ADS1115()

    # Note you can change the I2C address from its default (0x48), and/or the I2C
    # bus by passing in these optional parameters:
    #adc = Adafruit_ADS1x15.ADS1015(address=0x49, busnum=1)

    # Choose a gain of 1 for reading voltages from 0 to 4.09V.
    # Or pick a different gain to change the range of voltages that are read:
    #  - 2/3 = +/-6.144V
    #  -   1 = +/-4.096V
    #  -   2 = +/-2.048V
    #  -   4 = +/-1.024V
    #  -   8 = +/-0.512V
    #  -  16 = +/-0.256V
    # See table 3 in the ADS1015/ADS1115 datasheet for more info on gain.
    GAIN = 1

    instance = dht11.DHT11(pin=17)

    DEFAULT_CONFIG_PATH = 'config/config.json'

    with open(DEFAULT_CONFIG_PATH, 'r') as config_file:
        config = json.load(config_file)['temperatureSensor']
    print(config)

    # Configure Oauth2 access_token for the client application.  Here we have used
    # the device token for the configuration
    artikcloud.configuration = artikcloud.Configuration()
    artikcloud.configuration.access_token = config['deviceToken']

    # We create an instance of the Message API class which provides
    # the send_message() and get_last_normalized_messages() api call
    # for our example
    api_instance = artikcloud.MessagesApi()

    # Device_message - data that is sent to your device
    device_message = {}

    # We send random values to the 'temp' field for this FireSensor.
    # Let's send a random value between 0 and 200 for this demo.
    #device_message['temp'] = random.randrange(0,200);
    result = instance.read()

    humidity = 0
    temp_value = 0
    if result.is_valid():
        temp_value = result.temperature * 1.8 + 32
        device_message['temp'] = temp_value
        humidity = result.humidity
        print("Last valid input: " + str(datetime.datetime.now()))
        print("Temperature: %d F" % temp_value)
        print("Humidity: %d %%" % result.humidity)

    time.sleep(1)

    # Set the 'device id' - value from your config.json file
    device_sdid = config['deviceId']
    send_message(api_instance, device_message, device_sdid)

    if (humidity > 0):
        device_message = {}
        device_message['humidity'] = humidity
        send_message(api_instance, device_message, device_sdid)

    #sensor = BMP085.BMP085()
    #pressure = sensor.read_pressure()
    #print('Pressure = {0:0.2f} Pa'.format(pressure))
    air_qa_value = adc.read_adc(0, gain=GAIN)
    print("Air quality: %f " % air_qa_value)

    if (air_qa_value > 0):
        device_message = {}
        device_message['air_quality'] = air_qa_value
        #if (pressure > 0):
        #   device_message = {}
        #   device_message['pressure'] = pressure
        send_message(api_instance, device_message, device_sdid)

    db.execute("INSERT INTO {tn}  VALUES ((CURRENT_TIMESTAMP), {t}, {h},{a})"\
         .format(tn=table_name, t = temp_value, h = humidity, a =air_qa_value))
    db.commit()
    db.close()
Ejemplo n.º 16
0
 def setUp(self):
     configuration = artikcloud.Configuration()
     configuration.access_token = self.properties['user1.token']
     self.api = TokensApi()
Ejemplo n.º 17
0
room_id = [ "temp_hub",      "Living_Room_Temperature",      
            "temp_sensor00", "Bedroom_Temperature"]

nroom = len(room_id)
ns=2

#----------------- End Variables ------------------------------------------
#
###########################################################################



###########################################################################
#
#................... Setup Artik Cloud Communication ......................
artikcloud.configuration = artikcloud.Configuration()       # Configure Artik Cloud
artikcloud.configuration.access_token = device_token        # Set device token
device_sdid = device_id                                     # Set device id
api_instance = artikcloud.MessagesApi()                     # Get messaging API
#------------- End Artik Cloud Communication Setup ------------------------
#
###########################################################################


print ('\n\n --------- Connecting -------------- \n\n\n')
ser = serial.Serial(arduino,9600)           # Connect to Arduino

while(True):

  #######################################################################################
  #
Ejemplo n.º 18
0
 def setUp(self):
     configuration = artikcloud.Configuration();
     configuration.access_token = self.properties['device1.token']
     self.api = MessagesApi()