Skip to content

Instantly share code, notes, and snippets.

@socalal
Last active April 18, 2016 22:20
Show Gist options
  • Save socalal/bf4f7220759cfda4bfa1717913804702 to your computer and use it in GitHub Desktop.
Save socalal/bf4f7220759cfda4bfa1717913804702 to your computer and use it in GitHub Desktop.
Over-the-Air Node Configuration Loop - socalal
#!/usr/bin/python
# Created by Alan M. Orther - alan.orther@gmail.com
# This script is used to loops through nodes and send an over-the-air command.
import os
import time
# Create /tmp/ota_tools_logs/ directory if it does not already exist.
otatools_dir = "/tmp/ota_tools_logs/"
otatools_dir = os.path.expanduser(otatools_dir)
if not os.path.exists(otatools_dir):
os.makedirs(otatools_dir)
# Create or open and append to otatool.log file.
log = open(otatools_dir + 'otatool.log', 'a+')
# This is the list of nodes that will be used.
node_list = ["0x00033159", "0x000339CB", "0x00033741", "0x00033D7D",
"0x00033F23", "0x000337C0", "0x00033DAF", "0x00033DA3",
"0x000339D3", "0x0003339D", "0x00033E1E", "0x00033DFA",
"0x00033AC1", "0x00033BDF", "0x00034136", "0x00033BCA",
"0x00033DB8", "0x000330F3", "0x0003398F", "0x000339EC",
"0x00033629", "0x000333F8", "0x00033F2B", "0x00033DC4",
"0x00033D9E"]
# Top banner for set config.
log.write("\n********************* SET CONFIG **************************\n\n")
# Run OTA config tool on 1 node, wait 15 seconds, & run on another through list.
for n in node_list:
node_dec = int(n, 16)
node = "/opt/ulp/ami_tools_1.0/gw_ota_tools_emcm_1.10.7/"\
"emcm_ota_set_config_val.py --customer=nolinCustomer "\
"--key=bulkReadOffset --value=18000 --nodeId=%s >> /tmp/ota_tools_"\
"logs/otatool_output.log 2>&1" % n
node_discription = 'echo -e "\nNODE OUTPUT - hex-%s dec-%s" >> /tmp/'\
'ota_tools_logs/otatool_output.log' % (n, node_dec)
os.system(node_discription)
os.system(node)
log_write = "OTA set_config has been sent to hex-%s dec-%s -- %s\n" % \
(n, node_dec, time.strftime("%Y-%m-%d %H:%M:%S %Z"))
log.write(log_write)
print "Set_config sent to node hex-%s dec-%s" % (n, node_dec)
# Wait 15 seconds between sending the command to next node.
time.sleep(15)
# Sleep for 5 minutes so all the devices get the set config.
print "\nWaiting 5 minutes to start resetting devices.\n"
time.sleep(300)
# Make space between set config and device reset.
log.write("\n\n******************** DEVICE RESET ***********************\n\n")
# Run OTA reset tool on 1 node, wait 120 seconds, & run on next node in list.
for n in node_list:
node_dec = int(n, 16)
node = "/opt/ulp/ami_tools_1.0/gw_ota_tools_emcm_1.10.7/emcm_ota_reset.py "\
"--customer=nolinCustomer --resetMCM --nodeId=%s >> /tmp/ota_tools_"\
"logs/otatool_output.log 2>&1" % n
node_discription = 'echo -e "\nNODE OUTPUT - hex-%s dec-%s" >> /tmp/'\
'ota_tools_logs/otatool_output.log' % (n, node_dec)
os.system(node_discription)
os.system(node)
log_write = "OTA device reset has been sent to hex-%s dec-%s -- %s\n" % \
(n, node_dec, time.strftime("%Y-%m-%d %H:%M:%S"))
log.write(log_write)
print "Reset sent to node hex-%s dec-%s" % (n, node_dec)
# Wait 2 minutes between sending the command to next node.
time.sleep(120)
# Sleep for 10 minutes until the devices get reset & report to GW01 log (below).
print "\nWaiting 10 minutes to start reading the gateway and event logs."
time.sleep(600)
# Make space between device reset and gateway logs added to otatool logs.
log.write("\n\n******************* GATEWAY LOGS **************************\n\n")
# Scrape gateway log for data about these nodes and append to otatool log.
for n in node_list:
node_dec = int(n, 16)
log.write("\nGATEWAY LOG GREP for node hex-%s dec-%s" % (n, node_dec))
log_search = "cat /opt/ulp/gateway/instances/default/logs/gateway.log | "\
"grep %s >> /tmp/ota_tools_logs/otatool.log" % node_dec
os.system(log_search)
# Wait 30 seconds between grepping the gateway log for the next node.
time.sleep(30)
# Make space between device reset and gateway logs added to otatool logs.
log.write("\n\n******************** EVENT LOGS ***************************\n\n")
# Scrape event log for data about these nodes and append to otatool log.
for n in node_list:
node_dec = int(n, 16)
log.write("\nEVENT LOG GREP for node hex-%s dec-%s" % (n, node_dec))
log_search = "cat /opt/ulp/gateway/instances/default/logs/event.log | "\
"grep %s >> /tmp/ota_tools_logs/otatool.log" % node_dec
os.system(log_search)
# Wait 30 seconds between grepping the event log for the next node.
time.sleep(30)
# Finish up the script by closing file and quitting script.
print "\nThis script is finished.\n"
log.write("\nTHE SCRIPT HAS FINISHED.")
log.write("\nPLEASE CHECK /tmp/ota_tools_logs/otatool.log for the script log")
log.write("\nAND CHECK /tmp/ota_tools_logs/otatool_output.log for "
"the error and command output log.")
log.close()
print "Log file updated and closed.\n"
print "Closing script..."
time.sleep(2)
print "CLOSED"
quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment