diff --git a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.drone_analyzer.type-view/public/images/schematicsGuide.png b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.drone_analyzer.type-view/public/images/schematicsGuide.png index b247bf65e2..a755f05187 100644 Binary files a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.drone_analyzer.type-view/public/images/schematicsGuide.png and b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.drone_analyzer.type-view/public/images/schematicsGuide.png differ diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py index 8e502fa251..f82bd58d12 100755 --- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py +++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py @@ -63,8 +63,6 @@ if args.mode: iotUtils = __import__('iotUtils') httpServer = __import__('httpServer') # python script used to start a http-server to listen for operations # (includes the TEMPERATURE global variable) - mqttListener = __import__('mqttListener') # python script used to accept messages via mqtt - #xmppServer = __import__('xmppServer') # python script used to communicate with xmpp server if running_mode.RUNNING_MODE == 'N': Adafruit_DHT = __import__('Adafruit_DHT') # Adafruit library required for temperature sensing @@ -261,38 +259,12 @@ class ListenHTTPServerThread(object): def sigterm_handler(_signo, _stack_frame): print("[] received signal {}, exiting...".format(_signo)) sys.exit(0) - - -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# This is a Thread object for Server that listens for XMPP Messages -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -class ListenXMPPServerThread(object): - def __init__(self): - thread = threading.Thread(target=self.run, args=()) - thread.daemon = True # Daemonize thread - thread.start() # Start the execution - - def run(self): - pass - #xmppServer.main() -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# This is a Thread object for listening for MQTT Messages # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -class ListenMQTTThread(object): - def __init__(self): - thread = threading.Thread(target=self.run, args=()) - thread.daemon = True # Daemonize thread - thread.start() # Start the execution - def run(self): - mqttListener.main() -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ signal.signal(signal.SIGTERM, sigterm_handler) + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # The Main method of the RPi Agent # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -304,8 +276,6 @@ def main(): registerDeviceIP() # Call the register endpoint and register Device IP TemperatureReaderThread() # initiates and runs the thread to continuously read temperature from DHT Sensor ListenHTTPServerThread() # starts an HTTP Server that listens for operational commands to switch ON/OFF Led - # ListenXMPPServerThread() - # ListenMQTTThread() while True: try: if iotUtils.LAST_TEMP > 0: # Push data only if there had been a successful temperature read diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/deviceConfig.properties b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/deviceConfig.properties new file mode 100644 index 0000000000..489af70420 --- /dev/null +++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/deviceConfig.properties @@ -0,0 +1,33 @@ +# +# Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# +[Device-Configurations] +server-name=${SERVER_NAME} +owner=${DEVICE_OWNER} +deviceId=${DEVICE_ID} +device-name=${DEVICE_NAME} +controller-context=/raspberrypi/controller +https-ep=${HTTPS_EP} +http-ep=${HTTP_EP} +apim-ep=${APIM_EP} +mqtt-ep=${MQTT_EP} +xmpp-ep=${XMPP_EP} +auth-method=token +auth-token=${DEVICE_TOKEN} +refresh-token=${DEVICE_REFRESH_TOKEN} +push-interval=15 + + diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/httpServer.pyc b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/httpServer.pyc new file mode 100644 index 0000000000..3d8918bcc8 Binary files /dev/null and b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/httpServer.pyc differ diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/iotUtils.pyc b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/iotUtils.pyc new file mode 100644 index 0000000000..4a9ef3ac7e Binary files /dev/null and b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/iotUtils.pyc differ diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/mqttListener.py b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/mqttListener.py deleted file mode 100644 index 882a7ff6cf..0000000000 --- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/mqttListener.py +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/env python - -""" -/** -* 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 -* in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -**/ -""" - -import time -import iotUtils -import paho.mqtt.client as mqtt - - -# The callback for when the client receives a CONNACK response from the server. -def on_connect(client, userdata, flags, rc): - print("MQTT_LISTENER: Connected with result code " + str(rc)) - - # Subscribing in on_connect() means that if we lose the connection and - # reconnect then subscriptions will be renewed. - print ("MQTT_LISTENER: Subscribing with topic " + TOPIC) - client.subscribe(TOPIC) - - - -# The callback for when a PUBLISH message is received from the server. -def on_message(client, userdata, msg): - print( "MQTT_LISTENER: " + msg.topic + " " + str(msg.payload) ) - - request = str(msg.payload) - - resource = request.split(":")[0].upper() - state = request.split(":")[1].upper() - - print "MQTT_LISTENER: Resource- " + resource - - if resource == "TEMP": - pass - #request.send_response(200) - #request.send_header("Content-type", "text/plain") - #request.end_headers() - #request.wfile.write(LAST_TEMP) - # return - - elif resource == "BULB": - iotUtils.switchBulb(state) - -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# The Main method of the server script -# This method is invoked from RaspberryStats.py on a new thread -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -def main(): - - MQTT_ENDPOINT = iotUtils.MQTT_EP.split(":") - MQTT_IP = MQTT_ENDPOINT[1].replace('//','') - MQTT_PORT = int(MQTT_ENDPOINT[2]) - - DEV_OWNER = iotUtils.DEVICE_OWNER - DEV_ID = iotUtils.DEVICE_ID - - global TOPIC - TOPIC = "wso2/iot/" + DEV_OWNER + "/firealarm/" + DEV_ID - - print ("MQTT_LISTENER: MQTT_ENDPOINT is " + str(MQTT_ENDPOINT)) - print ("MQTT_LISTENER: MQTT_TOPIC is " + TOPIC) - - mqttClient = mqtt.Client() - mqttClient.on_connect = on_connect - mqttClient.on_message = on_message - - while True: - try: - mqttClient.connect(MQTT_IP, MQTT_PORT, 60) - print "MQTT_LISTENER: " + time.asctime(), "Connected to MQTT Broker - %s:%s" % (MQTT_IP, MQTT_PORT) - - # Blocking call that processes network traffic, dispatches callbacks and - # handles reconnecting. - # Other loop*() functions are available that give a threaded interface and a - # manual interface. - mqttClient.loop_forever() - - except (KeyboardInterrupt, Exception) as e: - print "MQTT_LISTENER: Exception in MQTTServerThread (either KeyboardInterrupt or Other)" - print ("MQTT_LISTENER: " + str(e)) - - mqttClient.disconnect() - print "MQTT_LISTENER: " + time.asctime(), "Connection to Broker closed - %s:%s" % (MQTT_IP, MQTT_PORT) - print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' - pass - - -if __name__ == '__main__': - iotUtils.setUpGPIOPins() - main() - diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/running_mode.pyc b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/running_mode.pyc new file mode 100644 index 0000000000..fb6fa37c2c Binary files /dev/null and b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/running_mode.pyc differ diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/xmppServer.py b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/xmppServer.py deleted file mode 100644 index 65d0779a2d..0000000000 --- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/xmppServer.py +++ /dev/null @@ -1,156 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -""" -/* - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -""" - -import sleekxmpp -import getpass -import sys -import ssl, pyasn1 - -from urllib import urlopen -import iotUtils -import running_mode - -# Python versions before 3.0 do not use UTF-8 encoding -# by default. To ensure that Unicode is handled properly -# throughout SleekXMPP, we will set the default encoding -# ourselves to UTF-8. -def initSleekXMPP(): - if sys.version_info < (3, 0): - from sleekxmpp.util.misc_ops import setdefaultencoding - setdefaultencoding('utf8') - else: - raw_input = input - from sleekxmpp.plugins.xep_0323.device import Device - -class IoT_TestDevice(sleekxmpp.ClientXMPP): - """ - A simple IoT device that can act as server or client - """ - - def __init__(self, jid, password): - sleekxmpp.ClientXMPP.__init__(self, jid, password) - self.add_event_handler("session_start", self.session_start) - self.add_event_handler("message", self.message) - self.device = None - self.releaseMe = False - self.beServer = True - - def beClientOrServer(self, server=True, clientJID=None): - self.beServer = True - - def testForRelease(self): - # todo thread safe - return self.releaseMe - - def doReleaseMe(self): - # todo thread safe - self.releaseMe = True - - def addDevice(self, device): - self.device = device - - def session_start(self, event): - self.send_presence() - self.get_roster() - # tell your preffered friend that you are alive - # self.send_message(mto='jocke@jabber.sust.se', mbody=self.boundjid.bare +' is now online use xep_323 stanza to talk to me') - - def message(self, msg): - if msg['type'] in ('chat', 'normal'): - print ("XMPP_SERVER: Got normal chat message" + str(msg)) - ip = urlopen('http://icanhazip.com').read() - msg.reply("XMPP_SERVER: Hi I am " + self.boundjid.full + " and I am on IP " + ip).send() - else: - print ("XMPP_SERVER: Got unknown message type %s", str(msg['type'])) - - -class TheDevice(Device): - """ - This is the actual device object that you will use to get information from your real hardware - You will be called in the refresh method when someone is requesting information from you - """ - - def __init__(self, nodeId): - Device.__init__(self, nodeId) - - def refresh(self, fields): - """ - the implementation of the refresh method - """ - # global LAST_TEMP - # self._set_momentary_timestamp(self._get_timestamp()) - # self._add_field_momentary_data(self, "Temperature", self.counter) - - self._add_field(name="Temperature", typename="numeric", unit="C") - self._set_momentary_timestamp(self._get_timestamp()) - self._add_field_momentary_data("Temperature", str(iotUtils.LAST_TEMP), flags={"automaticReadout": "true"}) - - -def main(): - XMPP_ENDP = iotUtils.XMPP_EP.split(":")[0] - - XMPP_ENDPOINT = iotUtils.XMPP_EP.split(":") - XMPP_IP = XMPP_ENDPOINT[1].replace('//', '') - XMPP_PORT = int(XMPP_ENDPOINT[2]) - - XMPP_OWN = iotUtils.DEVICE_OWNER - XMPP_JID = iotUtils.DEVICE_ID + "@" + XMPP_IP + "/raspi" - XMPP_PWD = iotUtils.AUTH_TOKEN - - print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" - print "XMPP_SERVER: Owner - " + XMPP_OWN - print "XMPP_SERVER: AccountID - " + XMPP_JID - print "XMPP_SERVER: AccountPass - " + XMPP_PWD - print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" - - xmpp = IoT_TestDevice(XMPP_JID, XMPP_PWD) - xmpp.ssl_version = ssl.PROTOCOL_SSLv3 - - xmpp.register_plugin('xep_0030') - xmpp.register_plugin('xep_0323') - xmpp.register_plugin('xep_0325') - - if XMPP_OWN: - # xmpp['xep_0030'].add_feature(feature='urn:xmpp:sn', - # node=opts.nodeid, - # jid=xmpp.boundjid.full) - - myDevice = TheDevice(XMPP_OWN) - # myDevice._add_field(name="Relay", typename="numeric", unit="Bool"); - myDevice._add_field(name="Temperature", typename="numeric", unit="C") - myDevice._set_momentary_timestamp("2013-03-07T16:24:30") - myDevice._add_field_momentary_data("Temperature", "23.4", flags={"automaticReadout": "true"}) - - xmpp['xep_0323'].register_node(nodeId=XMPP_OWN, device=myDevice, commTimeout=10) - xmpp.beClientOrServer(server=True) - - while not (xmpp.testForRelease()): - try: - xmpp.connect() - xmpp.process(block=True) - print ("XMPP_SERVER: Lost Connection") - except Exception as e: - print "XMPP_SERVER: Exception in XMPPServerThread (either KeyboardInterrupt or Other)" - print ("XMPP_SERVER: " + str(e)) - - -if __name__ == '__main__': - initSleekXMPP() - main() diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/testAgent.sh b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/testAgent.sh index 0e8c263acf..c3470b517a 100755 --- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/testAgent.sh +++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/testAgent.sh @@ -69,15 +69,6 @@ for f in ./deviceConfig.properties; do done cd $currentDir -git clone git://git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.python.git -cd org.eclipse.paho.mqtt.python -sudo python setup.py install - -cd $currentDir - -sudo apt-get install python-pip -sudo pip install sleekxmpp -sudo pip install pyasn1 pyasn1-modules while true; do read -p "Whats the time-interval (in seconds) between successive Data-Pushes to the WSO2-DC (ex: '60' indicates 1 minute) > " input