Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Last revision Both sides next revision | ||
user:kluong:feature_idea_-_staging_environment [2021/10/21 20:43] kluong |
user:kluong:feature_idea_-_staging_environment [2021/10/23 17:41] kluong [Gateway - testing changes] |
||
---|---|---|---|
Line 237: | Line 237: | ||
<code> | <code> | ||
- | psql -U control_tower_staging -d control_tower_staging -c "SHOW TABLES" | + | psql -U control_tower_staging -d control_tower_staging -c "SELECT * FROM pg_catalog.pg_tables WHERE schemaname='public'" |
</code> | </code> | ||
- | ==== Gateway Changes ==== | + | ==== Gateway Change - ability to pass in a database URI ==== |
I mentioned earlier we'll have to change the way the gateway works. This is the way the current code connects to the database: | I mentioned earlier we'll have to change the way the gateway works. This is the way the current code connects to the database: | ||
Line 273: | Line 273: | ||
</code> | </code> | ||
- | You'd need to see some RX frames on the tty device to test this properly though, since the gateway doesn't reach out to the database unless it sees a message to decode. | + | You'd need to see some RX frames on the tty device to test this properly though, since the gateway doesn't reach out to the database unless it sees a message to decode. |
- | To get this to work in production, you would have to modify the run_production.sh script, and also update the repository in production. | + | To get this to work in production, you would have to modify the run_production.sh script, and also update the repository production. |
+ | |||
+ | |||
+ | ==== Gateway - testing changes ==== | ||
+ | |||
+ | Options for testing | ||
+ | |||
+ | * Deploy to production - see what happens | ||
+ | * Deploy to staging - see what happens | ||
+ | * Setup an personal network (on your laptop, or maybe on the server) | ||
+ | * Connect the gateway to a "fake" xbee virtually, using a pty and another script | ||
+ | * Mock out the serial device completely in python | ||
+ | |||
+ | It's not necessarily practical to have hardware to test with all of the time and often hardware might not be available anyways. Luckily, with software we can work around this. | ||
+ | |||
+ | **Note: development for the gateway should generally be done in a linux-based environment.** | ||
+ | |||
+ | You can make a "fake" xbee network using the following python script: | ||
+ | |||
+ | <code> | ||
+ | import os | ||
+ | import errno | ||
+ | import time | ||
+ | |||
+ | def symlink_force(target, link_name): | ||
+ | try: | ||
+ | os.symlink(target, link_name) | ||
+ | except OSError as e: | ||
+ | if e.errno == errno.EEXIST: | ||
+ | os.remove(link_name) | ||
+ | os.symlink(target, link_name) | ||
+ | else: | ||
+ | raise e | ||
+ | |||
+ | def valid_packets(): | ||
+ | packets = {} | ||
+ | packets['heartbeat'] = "\x7e\x00\x16\x90\x00\x7d\x33\xa2\x00\x40\xe6\x4b\x5e\x03\xfd\x01\x00\x00\xff\xff\xf0\xfa\x23\x00\x2b\x02\xb2" | ||
+ | packets['apple'] = "\x7e\x00\x22\x90\x00\x7d\x33\xa2\x00\x40\x9f\x27\xa7\x29\x6c\x01\x01\x00\xff\xff\x80\x6f\x69\x3d\x06\x0f\x71\x7d\x33\x5a\x8a\x01\x00\x76\x01\x22\x00\x6e\x09\x55" | ||
+ | packets['cranberry'] = "\x7e\x00\x22\x90\x00\x7d\x33\xa2\x00\x41\x25\xe5\x88\x0c\x83\x01\x02\x00\xff\xff\x7c\xf3\x05\x00\xba\x0f\x5c\x08\x05\x00\x20\x73\x3b\x00\xdd\x8b\x01\x00\x7a" | ||
+ | packets['dragonfruit'] = "\x7e\x00\x24\x90\x00\x7d\x33\xa2\x00\x40\xe6\x72\x7d\x5e\x30\x18\x01\x03\x00\xff\xff\x30\xc8\x07\x00\x6b\x0d\xf4\x00\x06\x00\x00\x00\xb6\x72\x37\x00\xfe\x8b\x01\x00\x00" | ||
+ | packets['snapdragon'] = "\x7e\x00\x22\x90\x00\x7d\x33\xa2\x00\x40\xa3\x53\x7d\x5e\x20\x9c\x01\x04\x00\xff\xff\x12\xe4\x49\x00\xca\x0d\x44\x0c\x2c\x31\x01\x00\x2f\x01\x34\x00\x64\x00\xbb" | ||
+ | |||
+ | return packets | ||
+ | |||
+ | master_fd, slave_fd = os.openpty() | ||
+ | symlink_force(os.ttyname(slave_fd), '/tmp/fakexbee') | ||
+ | |||
+ | |||
+ | packets = valid_packets() | ||
+ | while True: | ||
+ | for key in packets: | ||
+ | os.write(master_fd, bytes(packets[key])) | ||
+ | time.sleep(1) | ||
+ | |||
+ | </code> | ||