def send_up_data(): # Replace 'geolocation' with the data stream you want to upload to path = '/DataPoint/geolocation.xml' # report current location in geojson. Replace the literals ('-100.3046875', etc) with # your lat long and you're good to go xml = '''<DataPoint> <data>{"type": "Point", "coordinates": {0}</data> <streamId>geolocation</streamId> </DataPoint>'''.format(get_gps_lat_long(cli_command("at\mibs=gps"))) idigidata.send_to_idigi(xml, path)
def __do_upload(self, document): filename = self.FILENAME_PREFIX + str(int(time.time() * 1000)) + ".xml" if "idigidata" in sys.modules and hasattr(idigidata, "send_to_idigi"): # new style result = idigidata.send_to_idigi(document, filename, self.COLLECTION, "text/plain", timeout=120) success, error, errmsg = result if not success: raise Exception, "idigidata error: %s" % repr(result) else: # old style idigidata_legacy.send_idigi_data(document, filename, self.COLLECTION, self.SECURE)
def send_up_data(): """Adam's stock function for uploading datapoints with mods by Brad""" global lastReading # Replace 'wr31ain' with the data stream to which you want to upload # Change the xml filename as needed path = 'DataPoint/{}.xml'.format(streamName) # Define datapoint(s) xml = '''<list> <DataPoint> <data>%s</data> <dataType>float</dataType> <units>V</units> <description>Raw voltage reading</description> <streamId>wr31ain</streamId> </DataPoint> <DataPoint> <data>%s</data> <dataType>float</dataType> <units>V</units> <description>Calculated voltage reading</description> <streamId>wr31vin</streamId> </DataPoint> </list>''' vdc, calc_vdc = read_gpio() z = xml % (vdc, calc_vdc) print "\n----------------------" print " Analog in: %s" % vdc print "Voltage in: %s" % calc_vdc # Only send to Remote Manager if conditionalReporting is set to false OR if # the reportingThreshold has been matched or exceeded if conditionalReporting is False or (round(calc_vdc - lastReading, voltageDecimal) >= reportingThreshold or round(lastReading - calc_vdc, voltageDecimal) >= reportingThreshold): print "Sending to Remote Manager..." idigidata.send_to_idigi(z, path) # Update the last reading to track for threashold changes lastReading = calc_vdc
def send_alert(self, message): """ Send a Datapoint alert :param message: str, Datapoint content :return response: tuple, Result code of datapoint upload attempt """ timestamp = millisecond_timestamp() dpoint = """\ <DataPoint> <dataType>STRING</dataType> <data>{0}</data> <timestamp>{1}</timestamp> <streamId>{2}</streamId> </DataPoint>""".format(message, timestamp, self.destination) response = idigidata.send_to_idigi(dpoint, "DataPoint/stream.xml") return response
def __do_upload(self, document): filename = (self.FILENAME_PREFIX + str(int(time.time() * 1000)) + ".xml") if 'idigidata' in sys.modules and hasattr(idigidata, 'send_to_idigi'): # new style result = idigidata.send_to_idigi(document, filename, self.COLLECTION, "text/plain", timeout=120) success, error, errmsg = result if not success: raise Exception, "idigidata error: %s" % repr(result) else: # old style idigidata_legacy.send_idigi_data(document, filename, self.COLLECTION, self.SECURE)
def flush_trace_cache(cache): try: try: cache_value = cache.getvalue() if len(cache_value) > 0: (success, error, errormsg) = idigidata.send_to_idigi(cache_value, "trace.log", append=False) if not success: print "Failed to Send over Data Service, error %d, message: %s" % (error, errormsg) except Exception, e: print "trace writer failed with exception: ", e finally: try: cache.truncate(0) except Exception, e: print "truncate failed with exception: ", e
def flush_trace_cache(cache): try: try: cache_value = cache.getvalue() if len(cache_value) > 0: (success, error, errormsg) =\ idigidata.send_to_idigi(cache_value, "trace.log", append=False) if not success: print "Failed to Send over Data Service, error %d, message: %s" % ( error, errormsg) except Exception, e: print "trace writer failed with exception: ", e finally: try: cache.truncate(0) except Exception, e: print "truncate failed with exception: ", e
def _upload(self, body, filename): loop_count = 0 while True: success, _, errmsg = idigidata.send_to_idigi(body, filename) if success: # transmitted successfully logger.info("Upload successful") break if errmsg.startswith("Request throttled."): logger.error("Device Cloud throttling, waiting") # Wait to try again time.sleep(self._RETRY_TIME) else: logger.warning("Unexpected Device Cloud error, data lost: %s", errmsg) break if loop_count >= self._RETRY_COUNT: logger.error("Exceeded retries, data lost") break loop_count = loop_count + 1
def __send_to_idigi(self, fname, data): ''' Push a file to Device Cloud. Returns boolean success value. ''' success = False collection = SettingsBase.get_setting(self, 'collection') try: self._tracer.debug('Attempting to upload %s to Device Cloud', fname) success, err, errmsg = idigidata.send_to_idigi( data, fname, collection) if success: self._tracer.debug('Successfully uploaded %s to Device Cloud', fname) else: self._tracer.error('Unsuccessful upload attempt of %s ' \ 'to Device Cloud. (Err: %s Errmsg: ' \ '%s)', fname, str(err), str(errmsg)) except Exception, e: self._tracer.error('Took an Exception during upload of %s' \ ' to Device Cloud: %s', fname, str(e))
def send_idigi_data(data, filename, collection=None, secure=True): return idigidata.send_to_idigi(data, filename, collection)