diff --git a/.gitignore b/.gitignore index c469f7d058..77d46f4f28 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,7 @@ hs_err_pid* carbonapps # Ignore generated device-type DBs -*.h2.db \ No newline at end of file +*.h2.db + +# Ignore generated .pyc pythin files +*.pyc \ No newline at end of file diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/README.md b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/README.md index 4bd587e8eb..b62a8bfc76 100644 --- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/README.md +++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/README.md @@ -1,4 +1,3 @@ - # Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. # WSO2 Inc. licenses this file to you under the Apache License, # Version 2.0 (the "License"); you may not use this file except diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/iotUtils.py b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/iotUtils.py index 639c8caf3d..b5bdc9b179 100644 --- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/iotUtils.py +++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/iotUtils.py @@ -20,7 +20,7 @@ **/ """ -import time, commands +import time import ConfigParser, os import random import running_mode @@ -111,16 +111,32 @@ def initGPIOModule(): # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Get the wlan0 interface via which the RPi is connected +# Get the IP-Address of the interface via which the RPi is connected # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def getDeviceIP(): - rPi_IP = commands.getoutput("ip route list | grep 'src '").split() - rPi_IP = rPi_IP[rPi_IP.index('src') + 1] - if len(rPi_IP) <= 16: - print "------------------------------------------------------------------------------------" - print "IOT_UTILS: IP Address of RaspberryPi: " + rPi_IP - print "------------------------------------------------------------------------------------" - return rPi_IP + # for POSIX system like MacOS and Linux + if os.name != "nt": + import commands + rPi_IP = commands.getoutput("ifconfig | grep inet | grep -v inet6 | grep -v 127.0.0.1 | awk '{print $2}'").split('\n') + if len(rPi_IP) > 0: + print "------------------------------------------------------------------------------------" + print "IOT_UTILS: IP Addresses of RaspberryPi: " + str(rPi_IP) + print "IOT_UTILS: IP Address used for HTTP Server: " + rPi_IP[0] + print "------------------------------------------------------------------------------------" + return rPi_IP[0] + # for windows systems + else: + from subprocess import check_output + rPi_IP = check_output("for /f \"tokens=14\" %a in ('ipconfig ^| findstr \"IPv4\" ^| findstr /v \"127.0.0.1\"') do echo %a", shell=True).decode() + rPi_IP = rPi_IP.replace('\r', '') + rPi_IP = rPi_IP.split('\n') + + for IPs in rPi_IP: + if IPs != '' and len(aps) < 16: + print("------------------------------------------------------------------------------------") + print("IOT_UTILS: IP Address used for HTTP Server: " + IPs) + print("------------------------------------------------------------------------------------") + return IPs # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~