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)
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"
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)
def test_send_message(self): """ Test case for send_message Send Message """ message = artikcloud.Message() message.type = "message" message.sdid = self.properties['device1.id'] message.ts = int(round(time.time() * 1000)) message.data = {'steps': 500} response = self.api.send_message(message) self.assertIsNotNone(response) messageid = response.data.mid self.assertIsNotNone(messageid, 'Message ID should not be None') # get normalized message from mid time.sleep(1) envelope = self.api.get_normalized_messages(mid=messageid) self.assertIsNotNone(envelope) self.assertEqual(envelope.size, 1) normalized = envelope.data[0] self.assertIsNotNone(normalized) self.assertEqual(normalized.mid, messageid) steps = normalized.data['steps'] self.assertIsNotNone(steps) self.assertEqual(steps, 500.0)
def send_rotation_data(self, phi, theta): try: data = artikcloud.Message() data.data = {'phi': phi, 'theta': theta} data.sdid = '96bcc8a85c394cb4a8858eef1af65fae' self._api_instance.send_message(data) except ApiException as e: print( "Exception when calling DeviceTypesApi->get_available_manifest_versions" )
def send_gps_data(self, long, lat): try: data = artikcloud.Message() data.data = {'long': long, 'lat': lat} data.sdid = '96bcc8a85c394cb4a8858eef1af65fae' self._api_instance.send_message(data) except ApiException as e: print( "Exception when calling DeviceTypesApi->get_available_manifest_versions" )
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)
def send_message(api_instance, device_message, device_sdid): # Custom timestamp ts = None data = artikcloud.Message(device_message, device_sdid, ts) # Debug Print oauth settings pprint(artikcloud.configuration.auth_settings()) try: # 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)
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
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)
try: get_str = gauges2.readline() get_str.replace("\n","") get_str.replace("\r","") if (0 < len(get_str)): weight = float(get_str) print(str(weight)) except KeyboardInterrupt: break except: pass if 100 < weight: # Create an instance of the API Class api_instance = artikcloud.MessagesApi() device_message = {} device_message['weight'] = weight device_sdid = 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) time.sleep(1) gauges2.close()
while True: ser_data = ser.readline() sp_data = ser_data.split("|") #dust=float(sp_data[1])+1 #rain=sp_data[2] #gas=int(sp_data[3])+1 #cds=(sp_data[4])+1 message = { 'dust': float(sp_data[1]), 'rain': sp_data[2], 'gas': int(sp_data[3]), 'brightness': int(sp_data[4]) } # create an instance of the API class api_instance = artikcloud.MessagesApi() data = artikcloud.Message( message, device_sdid, ts) # Message | Message object that is passed in the body try: # 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) time.sleep(20)
avg_temp = '%.2f'%avg_temp ac_msg['Average_Temperature'] = avg_temp print 'Sensor ID: %s '%sensor_id print 'Temperature: %s '%temp print 'Average Temperature: %s'%avg_temp jj=0 for js in range(ns): for jr in range(nroom): if sensor_id[js] == room_id[jr]: ac_msg[room_id[jr+1]] = temp[js] jj=jj+1 ts = None # Custom time stamp data = artikcloud.Message(ac_msg, device_sdid, ts) # Construct a Message object print ("\n\nMessage to Send:") print (data) print ('\nSending message at: ') os.system('echo $(date)') print ('\n\n') #--------------- End Make Message to Send -------------------------------- #....................... Send Message to Artik Cloud ...................... try: # Debug Print oauth settings pprint(artikcloud.configuration.auth_settings()) # Send Message
ctrComp('alloff') else: #STATE == start # determine LED state if LED == 'ON': digitalWrite(ledPin,HIGH) else: # LED OFF digitalWrite(ledPin,LOW) #-------------------------- Controller_end----------------------# # for sending message device_message = {} device_message['water_level'] = water_level device_sdid = config['device_id'] ts = None # Construct a Message Object for request data_instance = artikcloud.Message(device_message, device_sdid, ts) # Send Message try: if TRACE > 4: pprint(artikcloud.configuration.auth_settings()) api_response = api_instance.send_message(data_instance) # Send Message if TRACE > 4: pprint(api_response) except ApiException as e: pprint("Exception when calling MessagesApi->send_message: %s\n" % e) #=====================main()_definition_end=====================# if __name__ == "__main__": # initialize for i in (ledPin, waterInPin, waterOutPin, pumpPin):