def test_invalid_send_host_and_port(self):
        customCloud = CustomCloud(None,
                                  receive_host='receive.com',
                                  receive_port=9999)

        with pytest.raises(
                Exception,
                match=
                'Send host and port must be set before making this operation'):
            customCloud.sendMessage("hello")
Example #2
0
def sendPSK(args, data, is_sms=False):

    if not (args['devicekey']) and ('devicekey' in data):
        args['devicekey'] = data['devicekey']

    if not args['devicekey']:
        raise HologramError('Device key not specified')

    credentials = {'devicekey': args['devicekey']}

    recv = ''
    if not is_sms and (args['host'] is not None or args['port'] is not None):
        # we're using some custom cloud
        customCloud = CustomCloud(None,
                                  send_host=args['host'],
                                  send_port=args['port'])
        recv = customCloud.sendMessage(args['message'],
                                       timeout=args['timeout'])
        print(f'RESPONSE FROM CLOUD: {recv}')
    else:
        # host and port are default so use Hologram
        hologram = HologramCloud(credentials,
                                 authentication_type='csrpsk',
                                 network='cellular')
        send_message_helper(hologram, args, is_sms=is_sms)
Example #3
0
def wifiIsUp():
    print "WiFi is up!"


if __name__ == "__main__":
    print ''
    print 'Testing Custom Cloud class...'
    print ''

    send_host = raw_input("What is your host? ")
    send_port = raw_input("What is your port? ")

    customCloud = CustomCloud(None, send_host=send_host, send_port=send_port)

    customCloud.event.subscribe('message.sent', sayHello)

    print ""

    customCloud.event.subscribe('message.sent', sayHello2)
    customCloud.event.subscribe('wifi.connected', wifiIsUp)
    customCloud.event.unsubscribe('message.sent', sayHello)

    recv = customCloud.sendMessage("Hello, Python!")  # Send message to Cloud

    print "DATA RECEIVED: " + str(recv)

    print ''
    print 'Testing complete.'
    print ''
    print ''
    print 'Testing CustomCloud class...'
    print ''

    send_host = raw_input("What is your host? ")
    send_port = raw_input("What is your port? ")

    cloud = CustomCloud(None, send_host=send_host, send_port=send_port)

    print ''

    print 'Hologram SDK version:'
    print cloud.version

    cloud.event.broadcast('network.disconnected')

    recv = cloud.sendMessage("Hello, Python!1")  # Send message to Cloud
    print "DATA RECEIVED: " + str(recv)

    recv = cloud.sendMessage("Hello, Python!2")  # Send message to Cloud
    print "DATA RECEIVED: " + str(recv)

    recv = cloud.sendMessage("Hello, Python!3")  # Send message to Cloud
    print "DATA RECEIVED: " + str(recv)

    cloud.event.broadcast('network.connected')

    print ''
    print 'Testing complete.'
    print ''