from mqtt import MQTTClient, MQTTLibrary
orig_CTNGenerate_C = MQTTClient.CTNGenerate_C
def CTNGenerate_C(self, buildpath, locations):
res = orig_CTNGenerate_C(self, buildpath, locations)
is_SmartehCloud = self.GetParamsAttributes(u"MQTTClient.AuthType")["value"] == u"SmartehCloud"
location_str = "_".join(map(str, self.GetCurrentLocation()))
name_str = self.BaseParams.getName()
runtimefile_path = os.path.join(buildpath, "runtime_%s_mqtt_.py" % location_str)
runtimefile = open(runtimefile_path, 'w')
from runtime.spawn_subprocess import Popen, call, PIPE
LPCTopic = "/smarteh/"+common_functions.getLPCSerialFromMAC()+"/command"
def _{location}_topic_callback(topic, payload):
proc = Popen([os.path.join(os.path.dirname(common_functions.__file__), 'mqtt_command.sh')], stdin=PIPE)
proc.stdin.write(payload)
def _runtime_{location}_mqtt_start():
MQTT_subscribe("{name}", LPCTopic, _{location}_topic_callback)
def _runtime_{location}_mqtt_stop():
""".format(location = location_str,
return res + (("runtime_%s_mqtt.py" % location_str, open(runtimefile_path, "rb")),)
MQTTClient.CTNGenerate_C = CTNGenerate_C
orig___init__ = MQTTClient.__init__
self.SetParamsAttribute(u'MQTTClient.AuthType', u'SmartehCloud')
MQTTClient.__init__ = __init__
xsd_frags = re.split(r'(choice[^>]*>)', MQTTClient.XSD, 1, re.DOTALL)
<xsd:element name="SmartehCloud"/>
MQTTClient.XSD = "".join(xsd_frags)
orig_GetConfig = MQTTClient.GetConfig
res = orig_GetConfig(self)
if res["AuthType"] == "SmartehCloud":
"KeyStore": "/media/data/keystore/cloud/KeyStore.pem",
"TrustStore": "/media/data/keystore/cloud/TrustStore.pem"})
MQTTClient.GetConfig = GetConfig