def test_invalid_send_sms(self):
        customCloud = CustomCloud(None, 'test.com', 9999)

        temp = "hello"
        with pytest.raises(NotImplementedError,
                           match='Cannot send SMS via custom cloud'):
            customCloud.sendSMS('+1234567890', temp)
Esempio n. 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)
    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")
def run_modem_radio_off(args):
    cloud = CustomCloud(None, network='cellular')
    res = cloud.network.modem.radio_power(False)
    if res:
        print 'Modem radio disabled'
    else:
        print 'Failure to disable radio'
Esempio n. 5
0
def run_modem_location(args):
    cloud = CustomCloud(None, network='cellular')
    location_obj = cloud.network.location
    if location_obj is None:
        print('Location: Not Available')
    else:
        print('Location: ' + convert_location_into_json(location_obj))
Esempio n. 6
0
def run_modem_radio_on(args):
    cloud = CustomCloud(None, network='cellular')
    res = cloud.network.modem.radio_power(True)
    if res:
        print('Modem radio enabled')
    else:
        print('Failure to enable radio')
    def test_create_receive(self):
        customCloud = CustomCloud(None, receive_host='127.0.0.1',
                                  receive_port=9999, enable_inbound=False)

        assert customCloud.send_host == ''
        assert customCloud.send_port == 0
        assert customCloud.receive_host == '127.0.0.1'
        assert customCloud.receive_port == 9999
Esempio n. 8
0
def run_network_connect(args):
    cloud = CustomCloud(None, network='cellular')
    cloud.network.disable_at_sockets_mode()
    res = cloud.network.connect()
    if res:
        print('PPP session started')
    else:
        print('Failed to start PPP')
Esempio n. 9
0
def run_modem_signal(args):
    cloud = CustomCloud(None, network='cellular')

    if args['repeat'] != 0:
        while True:
            print('Signal strength: ' + cloud.network.signal_strength)
            handle_timeout(args['repeat'])
    else:
        print('Signal strength: ' + str(cloud.network.signal_strength))
Esempio n. 10
0
    def test_enable_inbound(self):

        with pytest.raises(
                Exception,
                match='Must set receive host and port for inbound connection'):
            customCloud = CustomCloud(None,
                                      send_host='receive.com',
                                      send_port=9999,
                                      enable_inbound=True)
Esempio n. 11
0
def run_modem_signal(args):
    cloud = CustomCloud(None, enable_inbound=False, network='cellular-ms2131')

    if args['repeat'] != 0:
        while True:
            print 'Signal strength: ' + cloud.network.signal_strength
            handle_timeout(args['repeat'])
    else:
        print 'Signal strength: ' + cloud.network.signal_strength
Esempio n. 12
0
def run_modem_connect(args):
    print('Note: "hologram modem connect" is deprecated '\
            'in favor of "hologram network connect"')
    cloud = CustomCloud(None, network='cellular')
    cloud.network.disable_at_sockets_mode()
    res = cloud.network.connect()
    if res:
        print('PPP session started')
    else:
        print('Failed to start PPP')
Esempio n. 13
0
def modem_connect():
    """
    establish ppp connection to hologram network
    """
    try:
        cloud = CustomCloud(None, network='cellular')
        cloud.network.disable_at_sockets_mode()
        cloud.network.connect()
    except Exception as e:
        print(e)
        hologram.modem_disconnect()
Esempio n. 14
0
def run_at_command(args):
    cloud = CustomCloud(None, network='cellular')
    cmd = ''
    if args['command'] is not None:
        cmd = args['command'].lstrip("AT")
    val = None
    if not cmd.endswith('?') and '=' in cmd:
        cmd, val = cmd.split('=')
    result, response = cloud.network.modem.command(cmd,
                                                   val,
                                                   timeout=args['timeout'])
    print('Response: ' + ''.join(map(str, response)) + f'\n{result}')
Esempio n. 15
0
def hologram_network_connect():
    hologram_network_disconnect()
    time.sleep(2)
    cloud = CustomCloud(None, network='cellular')
    cloud.network.disable_at_sockets_mode()
    res = cloud.network.connect()
    message = ""
    if res:
        message = "PPP session started"
    else:
        message = "Failed to start PPP"

    _output_message(message)
#!/usr/bin/env python2.7

import argparse
import os
from Hologram.HologramCloud import HologramCloud
from Hologram.CustomCloud import CustomCloud

credentials = {'devicekey': ''}
hologram_cloud = HologramCloud(credentials, network='cellular')
custom_cloud = CustomCloud(dict(), send_host='localhost', send_port=9999, network='cellular')

def send_messages(messages, is_custom_cloud=False):
    if len(messages) < 1:
        return

    if is_custom_cloud:
        cloud_obj = custom_cloud
    else:
        cloud_obj = hologram_cloud

    result = cloud_obj.network.connect()
    if result == False:
        print ' Failed to connect to cell network'
        return

    for message in messages:
        m = message + "\n"
        response = cloud_obj.sendMessage(m)

        if is_custom_cloud:
            result_string = 'Message sent successfully'
Esempio n. 17
0
def run_modem_sim(args):
    cloud = CustomCloud(None, network='cellular')
    print('ICCID: ' + str(cloud.network.iccid))
Esempio n. 18
0
def run_modem_operator(args):
    cloud = CustomCloud(None, enable_inbound=False, network='cellular-ms2131')
    print 'Operator: ' + cloud.network.operator
Esempio n. 19
0
def run_modem_sim(args):
    cloud = CustomCloud(None, enable_inbound=False, network='cellular-ms2131')
    print 'ICCID: ' + cloud.network.iccid
Esempio n. 20
0
def run_modem_location(args):
    cloud = CustomCloud(None, enable_inbound=False, network='cellular-ms2131')
    location_obj = cloud.network.location
    print 'Location: ' + convert_location_into_json(location_obj)
Esempio n. 21
0
def run_modem_type(args):
    cloud = CustomCloud(None, enable_inbound=False, network='cellular-ms2131')
    print 'Type: ' + str(cloud.network.active_modem_interface)
Esempio n. 22
0
def run_modem_connect(args):
    cloud = CustomCloud(None, network='cellular')
    cloud.network.disable_at_sockets_mode()
    cloud.network.connect()
    print 'PPP session started'

if __name__ == "__main__":
    print ""
    print ""
    print "Testing Hologram Cloud class..."
    print ""
    print "* Note: You can obtain CSRPSK IDs and Keys from the Devices page"
    print "* at https://dashboard.hologram.io"
    print ""

    receive_host = raw_input("What is your host? ")
    receive_port = raw_input("What is your port? ")

    customCloud = CustomCloud(None,
                              receive_host=receive_host,
                              receive_port=receive_port,
                              enable_inbound=True)

    customCloud.event.subscribe('message.received', sayMessageReceived)

    # send your messages here.
    print 'sleeping for 20 seconds'
    print 'Send your messages now!'
    time.sleep(20)
    print "woke up..."

    customCloud.closeReceiveSocket()
    customCloud.openReceiveSocket()

    print 'sleeping for another 20 seconds'
    print 'Send your messages now!'
Esempio n. 24
0
def run_network_connect(args):
    cloud = CustomCloud(None, network='cellular')
    cloud.network.disable_at_sockets_mode()
    cloud.network.connect()
Esempio n. 25
0
    #Voltage Logic
    if voltage <= 10:  #Battery below 10V
        automationhat.light.warn.on()
        print("Warning: Voltage Low")
        print("Voltage: " + str(voltage) + "V")
    else:
        automationhat.light.warn.off()
        print("Voltage: " + str(voltage) + "V")

    #Moisture Logic
    moisturepercent = moisture * 100
    moisturepercent = (float("{0:.2f}".format(moisturepercent)))
    print("Soil Moisture Percentage: " + str(moisturepercent) + "%")

    #Grabs location data according to cell service
    cloud = CustomCloud(None, network='cellular')
    location_obj = cloud.network.location
    t = hologram_modem.convert_location_into_json(location_obj)

    #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
    }
Esempio n. 26
0
def run_modem_version(args):
    cloud = CustomCloud(None, network='cellular')
    version = cloud.network.modem.version
    print('Modem version: ' + version)
Esempio n. 27
0
def run_modem_imei(args):
    cloud = CustomCloud(None, network='cellular')
    imei = cloud.network.modem.imei
    print('IMEI: ' + imei)
Esempio n. 28
0
def run_modem_type(args):
    cloud = CustomCloud(None, network='cellular')
    print('Type: %s' % cloud.network.description)
Esempio n. 29
0
def run_modem_operator(args):
    cloud = CustomCloud(None, network='cellular')
    print('Operator: ' + str(cloud.network.operator))
Esempio n. 30
0
def run_modem_reset(args):
    cloud = CustomCloud(None, network='cellular')
    cloud.network.modem.reset()
    print('Restarted modem')