def test_get_result_string(self): hologram = HologramCloud(credentials, enable_inbound = False) assert hologram.getResultString(0) == 'Message sent successfully' assert hologram.getResultString(1) == 'Connection was closed so we couldn\'t read the whole message' assert hologram.getResultString(2) == 'Failed to parse the message' assert hologram.getResultString(3) == 'Auth section of the message was invalid' assert hologram.getResultString(-1) == 'Unknown error' assert hologram.getResultString(7) == 'Unknown response code'
class HologramSender: def __init__(self): self.hologram = HologramCloud(dict(), network='cellular') self.connected = self.hologram.network.connect() if self.connected == False: print(' Failed to connect to cell network') def __del__(self): self.hologram.network.disconnect() def foundPerson(self, name, ID, location, phone): payload = self.formatPayload(name, ID, location, phone) return self.sendAlert() def formatPayload(self, name, ID, location, phone): payloadDict = {} payloadDict['name'] = name payloadDict['ID'] = ID payloadDict['phoneNumber'] = phone payloadDict['location'] = location payloadDict['datetime'] = datetime.datetime.now().strftime( "%Y-%m-%d %H:%M:%S") jsonPayload = json.dumps(payloadDict) self.payload = jsonPayload def sendAlert(self): self.responseCode = self.hologram.sendMessage(self.payload, topics=["waldo-edge"]) return self.hologram.getResultString(self.responseCode)
def test_get_result_string(self): hologram = HologramCloud(credentials, enable_inbound=False) assert hologram.getResultString(-1) == 'Unknown error' assert hologram.getResultString(0) == 'Message sent successfully' assert hologram.getResultString( 1 ) == 'Connection was closed so we couldn\'t read the whole message' assert hologram.getResultString(2) == 'Failed to parse the message' assert hologram.getResultString( 3) == 'Auth section of the message was invalid' assert hologram.getResultString(4) == 'Payload type was invalid' assert hologram.getResultString(5) == 'Protocol type was invalid' assert hologram.getResultString( 6) == 'Internal error in Hologram Cloud' assert hologram.getResultString( 7) == 'Metadata was formatted incorrectly' assert hologram.getResultString(8) == 'Topic was formatted incorrectly'
sys.path.append("..") sys.path.append("../..") from Hologram.HologramCloud import HologramCloud if __name__ == "__main__": print "" print "" print "Testing Hologram Cloud class..." print "" print "* Note: You can obtain device keys from the Devices page" print "* at https://dashboard.hologram.io" print "" logging.basicConfig(level=logging.DEBUG, format="%(levelname)s: %(message)s") hologram = HologramCloud(dict(), authentication_type='sim-otp', network='cellular') result = hologram.network.connect() if result == False: print 'Failed to connect to cell network' recv = hologram.sendMessage("one two three!", topics = ["TOPIC1","TOPIC2"], timeout = 3) print 'RESPONSE MESSAGE: ' + hologram.getResultString(recv) hologram.network.disconnect()
from Hologram.HologramCloud import HologramCloud hologram = HologramCloud(dict(), network='cellular') result = hologram.network.connect() if result == False: print ' Failed to connect to cell network' response_code = hologram.sendMessage("hello, world 1!") print hologram.getResultString( response_code) # Prints 'Message sent successfully'. response_code = hologram.sendMessage("hello, world 2!", topics=["example-topic"]) hologram.network.disconnect()
#!/usr/bin/python # -*- coding: utf-8 -*- import sys, os os.system("sh /home/pi/rpifiles/vedirect/updatevars.sh") sys.path.insert(0, '/home/pi/rpifiles/RPI_SSD1306/') import sigpower from Hologram.HologramCloud import HologramCloud hologram = HologramCloud(dict(), network='cellular') var_vpv = sigpower.var_vpv var_batt = sigpower.var_batt var_bars = sigpower.var_bars var_op = sigpower.var_op result = hologram.network.connect() if result == False: print ' Failed to connect to cell network' response_code = hologram.sendMessage("Panel is " + str(var_vpv) + " - Batt is " + str(var_batt) + " - Network is " + str(var_op) + " with " + str(var_bars) + " bars of signal", topics=["Gulch"], timeout=10) print hologram.getResultString(response_code) hologram.network.disconnect()
from Hologram.HologramCloud import HologramCloud credentials = {'devicekey': '^hD8&#%H'} if __name__ == "__main__": print "" print "" print "Testing Hologram Cloud class..." print "" print "* Note: You can obtain device keys from the Devices page" print "* at https://dashboard.hologram.io" print "" hologram = HologramCloud(credentials, network='cellular', authentication_type='csrpsk' ) #HologramCloud(dict(), network='cellular') print 'Cloud type: ' + str(hologram) startMsg = hologram.sendSMS( "+34693608737", "Hello!! If you know Clemente, send him a Whatsapp! ;)") # enter your mobile number in the space above, area code required #sleep(60) # lets allow a little time for the cellular interface to restart print 'RESPONSE MESSAGE: ' + hologram.getResultString(startMsg) #recv = hologram.sendMessage('one two three!', # topics = ['TOPIC1','TOPIC2'], # timeout = 3) #print 'RESPONSE MESSAGE: ' + hologram.getResultString(recv)
credentials = PrivateData.settings['credentials'] phonehome = PrivateData.settings['mothership'] while 1: try: hg = HologramCloud(credentials, network='cellular', authentication_type='csrpsk') hg.enableSMS() print 'Starting Pentest Bot v1.0! ...\nMessaging mothership' smsSend = hg.sendSMS(phonehome, "Pentest Bot v1.0 reporting on Duty!") print hg.getResultString(smsSend) # Let us wait for command to act on print "Waiting for Mothership's message ..." while 1: recvCommand = hg.popReceivedSMS() command = '' if recvCommand is not None: print recvCommand command = recvCommand.message hg.sendSMS(phonehome, 'On it Boss! please be patient...') time.sleep(3)
# respond with the cellular position if RESPOND_WITH[1] == 'g' and gpsLatitude != 0.0: latitude, longitude = gpsLatitude, gpsLongitude origin = 'GPS' # Otherwise the requested data is the cellular position. # In the future the default behavior might change so # let's stick with 'c' means cellular position here and # the default is the same else: latitude, longitude = getCoordinates() origin = 'Cellular' # 's' is indicating that the response needs to be an SMS if RESPOND_WITH[0] == 's': response = origin + ' coordinates of your bike: https://maps.google.com/maps?q=' + str(latitude) + ',' + str(longitude) topic = 'sms' # Otherwise the response needs to be an SMS. # In the future the default behavior might change so # let's stick with 'e' means reponse needs to be and e-mail # and the default behavior is the same else: response = '{"latitude":"' + str(latitude) + '","longitude":"' + str(longitude) + '","origin":"'+ origin +'"}' topic = 'email' print 'Response: ' + response # Sending the data to the Hologram Cloud. It will do the # necessary routing, data handling response_code = hologram.sendMessage(response, topic) if 'Message sent successfully' == hologram.getResultString(response_code): print 'Message sent successfully' else: print 'Failed to send message'
from Hologram.HologramCloud import HologramCloud import os credentials = {'devicekey': '8K0Dyq*7'} hologram = HologramCloud(credentials, network='cellular') connected = 0 while not (connected == 1): os.system("sudo hologram network disconnect") if connected == 0: print "Not Connected (%d)\n -> Connecting" % (connected) hologram.network.connect(timeout=10) else: print "Trying to Reconnect (%d)" % (connected) hologram.network.disconnect() hologram.network.connect(timeout=10) connected = hologram.network.getConnectionStatus() print "Connected!" msg_err = hologram.sendMessage("I'm alive", timeout=7) if msg_err == 0: print "WE OUT HERE!!!!" else: print hologram.getResultString(msg_err)
dueno.activar_sistema(cloud) while True: sms = dueno.a_d_sms(cloud) #print sms if sms == 'D': activo = 'D' alerta = False ciclo = 2 gpio.output(13, False) response = 'Sistema de seguridad desactivado' recv = cloud.sendMessage(response, topics=['TRIGGER_DESACTIVAR'], timeout=3) print cloud.getResultString(recv) elif sms == 'A': activo = 'A' response = 'Sistema de seguridad activado' recv = cloud.sendMessage(response, topics=['TRIGGER_ACTIVAR'], timeout=3) print cloud.getResultString(recv) #Si es 'U' se mantiene el valor de activo if alerta == True: ciclo = 10 #print "Modo Alerta" gsmlatitude, gsmlongitude = getCoordinates() response = 'Coordenadas de la maquina: https://maps.google.com/maps?q=' + str( gsmlatitude) + ',' + str(gsmlongitude) recv = cloud.sendSMS("+14439044822", response)
#Grabs Latitude and Longitude from location data latitude = (float(t[60:70])) longitude = (float(t[87:98])) #Constructs payload of information to be sent payload = { "Voltage": voltage, "Moisture": moisturepercent, "Temperature": tempf, "Latitude": latitude, "Longitude": longitude } #Prints Kind of Internet Connection hologram = HologramCloud(dict(), network='cellular') print('Cloud type: ' + str(hologram)) #Sends Moisture and Voltage to Hologram recv = hologram.sendMessage(json.dumps(payload)) # Prints ('Message sent successfully') if message sent succesfully print('RESPONSE MESSAGE: ' + hologram.getResultString(recv)) #Turns on Comms Light if succesfully sent if hologram.getResultString(recv) == 1: automationhat.light.comms.on() #Waits to send data again time.sleep(refreshrate)
end_char = (n * 5000) section_of_image = encoded_string[start_char:end_char] message = "".join([ "stamp", divider, str(timestamp), divider, "cluster_order", divider, str(n), divider, "number_of_fragments", divider, str(num_of_messages), divider, "total_character_count", divider, str(character_count), divider, "content", divider, section_of_image ]) sending_msg_string = "Sending message %d" % (n) logger.debug(sending_msg_string) response_code = hologram.sendMessage(message, topics=["pi-one"]) hologram_result_string = hologram.getResultString(response_code) logger.debug(hologram_result_string) sleep(2) final_modem_disconnect = hologram.network.modem.disconnect() final_network_disconnect = hologram.network.disconnect() final_disconnections_string = "FINAL DISCONNECTIONS => Network: " + str( final_network_disconnect) + " Modem: " + str( final_modem_disconnect) logger.debug(final_disconnections_string) if os.path.exists(image_path): os.remove(image_path) file_removed_string = image_title + " removed." logger.debug(file_removed_string)
def alarm(pin,value): current_date = datetime.datetime.now() credentials = {'devicekey': 'LMaCQ?]G'} hologram = HologramCloud(credentials, network='cellular', authentication_type='csrpsk') if int(value[0]) == 1: blynk.virtual_write(13, current_date.strftime("%Y-%m-%d %H:%M:%S")) ### gather/write GPS vehicle data ### gps_data = gather_gps_data() vehicle_lat = gps_data[0] vehicle_lon = gps_data[1] vehicle_alt = gps_data[2] blynk.virtual_write(25, round(vehicle_lat,5)) blynk.virtual_write(26, round(vehicle_lon,5)) blynk.virtual_write(35, vehicle_alt) ### send activation SMS ### recv = hologram.sendSMS('+12069725002', 'AutoMOC Alarm Enabled. System has confirmed network connectivity') print('RESPONSE MESSAGE: ' + hologram.getResultString(recv)) print ('Sending text') ### geofence alarm ### vehicle_location = (vehicle_lat, vehicle_lon) print (vehicle_location) time.sleep(5) while True: print('Checking Alarm Status and Geofence alarm') if int(value[0]) == 1: alarm_gps_data = gather_gps_data() alarm_lat = alarm_gps_data[0] alarm_lon = alarm_gps_data[1] current_location = (alarm_lat, alarm_lon) print (current_location) displacement = distance.distance(vehicle_location, current_location).km print (displacement) alarm_trigger = 30 ### trigger alarm ### if int(value[0]) ==1 and displacement > alarm_trigger: print('Geofence Alarm TRIPPED') alarm_recv = hologram.sendSMS('+12069725002', 'AutoMOC Geofence Alarm TRIPPED. Go to InitialState.com for real-time tracking updates.') print('RESPONSE MESSAGE: ' + hologram.getResultString(alarm_recv)) streamer = Streamer(bucket_name="GPS_Tracker", bucket_key="GPS_Tracker", access_key="ist_xWKrfgU6MntKcQukAg0ohqZ0Dh7FFQYb") while True: print ('Streaming data to InitialState.com') print ( 'CPU time->' + datetime.now().time()) streamer.log("Location", "{lat},{lon}".format(lat=gather_gps_data()[0],lon=gather_gps_data()[1])) streamer.log("speed",gather_gps_data()[3]) time.sleep(10) continue ### alarm not triggered but armed ### elif int(value[0]) == 1 and displacement < alarm_trigger: print('Alarm not tripped, continuing period checks') time.sleep(5) continue ### alarm toggled off ### elif int(value[0]) == 0: print('Alarm toggled off-1') break continue time.sleep(5) else: break else: print('Alarm toggled off')