|
| 1 | +import paho.mqtt.client as mqtt |
| 2 | +from argparse import ArgumentParser |
| 3 | + |
| 4 | +class PacketGenerator(): |
| 5 | + OPENBENCHMARK_SENDPACKET_TOPIC = 'openbenchmark/experimentId/000/command/sendPacket' |
| 6 | + |
| 7 | + def __init__(self): |
| 8 | + self.parser = ArgumentParser() |
| 9 | + self._addParserArgs() |
| 10 | + |
| 11 | + self.argspace = self.parser.parse_args() |
| 12 | + |
| 13 | + self.confirmable = self.argspace.confirmable |
| 14 | + self.mqttBroker = self.argspace.mqttBroker |
| 15 | + self.payloadLen = self.argspace.mqttBroker |
| 16 | + self.destEui64 = self.argspace.destEui64 |
| 17 | + self.srcEui64 = self.argspace.srcEui64 |
| 18 | + |
| 19 | + # mqtt client |
| 20 | + self.mqttClient = mqtt.Client('generateSendPacket') |
| 21 | + self.mqttClient.connect(self.mqttBroker) |
| 22 | + |
| 23 | + command = { |
| 24 | + 'token' : '123', |
| 25 | + 'source' : self.srcEui64, |
| 26 | + 'destination' : self.destEui64, |
| 27 | + 'packetsInBurst' : 1, |
| 28 | + 'packetToken' : [0, 1, 2, 3, 4], |
| 29 | + 'packetPayloadLen' : 10, |
| 30 | + 'confirmable' : self.confirmable |
| 31 | + } |
| 32 | + |
| 33 | + self.mqttClient.publish( |
| 34 | + topic=self.OPENBENCHMARK_SENDPACKET_TOPIC, |
| 35 | + payload=json.dumps(command), |
| 36 | + ) |
| 37 | + |
| 38 | + def _addParserArgs(self): |
| 39 | + self.parser.add_argument('-c', '--confirmable', |
| 40 | + dest='confirmable', |
| 41 | + default=False, |
| 42 | + action='store', |
| 43 | + help='Whether a packet should be ack-ed at the app layer' |
| 44 | + ) |
| 45 | + self.parser.add_argument('-p', '--payloadLen', |
| 46 | + dest='payloadLen', |
| 47 | + default=10, |
| 48 | + action='store', |
| 49 | + help='Length of the payload in the packet to be sent.' |
| 50 | + ) |
| 51 | + self.parser.add_argument('-d', '--destEui64', |
| 52 | + dest='destEui64', |
| 53 | + default='', |
| 54 | + action='store', |
| 55 | + help='Destination EUI-64.' |
| 56 | + ) |
| 57 | + self.parser.add_argument('-s', '--srcEui64', |
| 58 | + dest='srcEui64', |
| 59 | + default='', |
| 60 | + action='store', |
| 61 | + help='Source EUI-64.' |
| 62 | + ) |
| 63 | + self.parser.add_argument('-b', '--mqttBroker', |
| 64 | + dest='mqttBroker', |
| 65 | + default='argus.paris.inria.fr', |
| 66 | + action='store_true', |
| 67 | + help='MQTT broker to use' |
| 68 | + ) |
| 69 | + |
| 70 | + def _on_mqtt_connect(self): |
| 71 | + pass |
| 72 | + |
| 73 | + def _on_mqtt_message(self): |
| 74 | + pass |
| 75 | + |
| 76 | +if __name__ == '__main__': |
| 77 | + PacketGenerator() |
0 commit comments