From d5871f892366c1c02dd7414243e9192854e948ee Mon Sep 17 00:00:00 2001 From: gitlab-runner Date: Sun, 3 Nov 2024 23:14:42 -0600 Subject: [PATCH] Upload ota-update 4.3.2.1052 [2846] --- RELEASE.md | 5 ++ scripts/WiFi_Ethernet/ota_update.json | 10 +-- scripts/WiFi_Ethernet/publisher.py | 111 ++++++++++++++++++-------- source/cy_ota_agent.c | 8 +- version.xml | 2 +- 5 files changed, 94 insertions(+), 42 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index 7a09eae..bb066d2 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -6,6 +6,11 @@ See the [README.md](./README.md) for a complete description of the OTA library. ## Changelog +### v4.3.2 + +- Bug fixes. +- Minor Documentation updates. + ### v4.3.1 - Minor Documentation updates. diff --git a/scripts/WiFi_Ethernet/ota_update.json b/scripts/WiFi_Ethernet/ota_update.json index 49faed2..c39cd04 100644 --- a/scripts/WiFi_Ethernet/ota_update.json +++ b/scripts/WiFi_Ethernet/ota_update.json @@ -1,13 +1,13 @@ { "Message":"Update Available", - "Manufacturer":"Express Widgits Corporation", - "ManufacturerId":"EWCO", - "Product":"Easy Widgit", + "Manufacturer":"Infineon", + "ManufacturerId":"ABCD123", + "Product":"EFGH456", "SerialNumber":"ABC213450001", "Board":"CY8CPROTO_062_4343W", - "Version": "2.0.0", + "Version":"2.0.0", "Connection":"MQTT", - "Broker": "", + "Broker":"", "Port": "", "UniqueTopicName":"replace" } diff --git a/scripts/WiFi_Ethernet/publisher.py b/scripts/WiFi_Ethernet/publisher.py index c9ba128..647ba03 100644 --- a/scripts/WiFi_Ethernet/publisher.py +++ b/scripts/WiFi_Ethernet/publisher.py @@ -9,11 +9,12 @@ import time import traceback import re +import ssl random.seed() # -# This is the MQTT Publisher for OTA Update device updating. +# This is the MQTT Publisher for performing OTA firmware update. # It is intended to be used with an MQTT Broker that does NOT # have the ability to save OTA Images. This allows Devices # to connect at any time and request an update. @@ -192,7 +193,15 @@ # Defines #============================================================================== -KIT = "CY8CPROTO_062_4343W" +# Board or Target name +BOARD = "APP_CY8CPROTO_062_4343W" +BUILD_CONFIG = "Debug" + +print("BOARD:",BOARD) +print("BUILD_CONFIG:",BUILD_CONFIG) + +# Kit or Device name +KIT = BOARD.replace("APP_","") SEND_IMAGE_MQTT_CLIENT_ID = "OTASend" @@ -207,7 +216,7 @@ BAD_JSON_DOC = "MALFORMED JSON DOCUMENT" # Bad incoming message -UPDATE_AVAILABLE_REQUEST = "Update Availability" # Device requests if there is an Update avaialble +UPDATE_AVAILABLE_REQUEST = "Update Availability" # Device requests if there is an Update available SEND_UPDATE_REQUEST = "Request Update" # Device requests Publisher send the OTA Image SEND_DIRECT_UPDATE = "Send Direct Update" # Device sent Update Direct request SEND_CHUNK = "Request Data Chunk" # Device sent Request for a chunk of the data file @@ -235,16 +244,19 @@ # Mosquitto works sometimes - it is a test server for the Mosquitto project # # Set the Broker using command line arguments "-b amazon" -# AMAZON_BROKER_ADDRESS = "a33jl9z28enc1q-ats.iot.us-west-1.amazonaws.com" -AMAZON_BROKER_ADDRESS = "a33jl9z28enc1q-ats.iot.us-east-1.amazonaws.com" +AMAZON_BROKER_ADDRESS = "xxxxxxxxx-ats.iot.us-west-2.amazonaws.com" # Set the Broker using command line arguments "-b eclipse" -ECLIPSE_BROKER_ADDRESS = "mqtt.eclipseprojects.io" +ECLIPSE_BROKER_ADDRESS = "mqtt.eclipse.org" # Set the Broker using command line arguments "-b mosquitto" MOSQUITTO_BROKER_ADDRESS = "test.mosquitto.org" -# default is mosquitto -BROKER_ADDRESS = MOSQUITTO_BROKER_ADDRESS + +# Set the Broker using command line arguments "-b mosquitto_local" +MOSQUITTO_BROKER_LOCAL_ADDRESS = "192.168.0.10" + +# default is local Mosquitto +BROKER_ADDRESS = MOSQUITTO_BROKER_LOCAL_ADDRESS TLS_ENABLED = False # turn on with "tls" argument on command line when invoking this script @@ -253,8 +265,7 @@ PUBLISHER_SUBSCRIBE_QOS = 1 # AWS broker does not support QOS of 2 # Path to the firmware image -#OTA_IMAGE_FILE = "../bld/ota-update/CY8CPROTO-062-4343W/Debug/ota-update.bin" -OTA_IMAGE_FILE = "ota-update.bin" +OTA_IMAGE_FILE = "" # Paho MQTT client settings MQTT_KEEP_ALIVE = 60 # in seconds @@ -313,8 +324,10 @@ def signal_handling(signum,frame): terminate = True # take over the signals (SIGINT - MAC & Linux, SIGBREAK - Windows -signal.signal(signal.SIGINT,signal_handling) -signal.signal(signal.SIGBREAK,signal_handling) +if sys.platform == 'win32': + signal.signal(signal.SIGBREAK,signal_handling) +else: + signal.signal(signal.SIGINT,signal_handling) #============================================================================== # Logging functions @@ -424,7 +437,7 @@ def do_chunking(image_file, whole_file, file_offset, send_size): print(" CHUNK Queued " + str(payload_index) + " chunks") return pub_mqtt_msgs,pub_total_payloads - return pub_mqtt_msgs,pub_total_payloads + return pub_mqtt_msgs,pub_total_payloads # ----------------------------------------------------------- # parse_incoming_request() @@ -540,7 +553,11 @@ def send_image_chunk_thread(message_string, unique_topic): send_client.on_connect = on_send_connect send_client.on_publish = on_send_publish if TLS_ENABLED: - send_client.tls_set(ca_certs, certfile, keyfile) + if BROKER_ADDRESS == MOSQUITTO_BROKER_LOCAL_ADDRESS: + send_client.tls_set(ca_certs, certfile, keyfile, cert_reqs=ssl.CERT_NONE) + send_client.tls_insecure_set(True) + else: + send_client.tls_set(ca_certs, certfile, keyfile) send_client.connect(BROKER_ADDRESS, BROKER_PORT, MQTT_KEEP_ALIVE) while send_client.connected_flag == False: send_client.loop(0.1) @@ -563,7 +580,7 @@ def send_image_chunk_thread(message_string, unique_topic): result,messageID = send_client.publish(unique_topic, pub_mqtt_msgs[0], PUBLISHER_PUBLISH_QOS) while send_client.publish_mid != messageID: send_client.loop(0.1) - time.sleep(1) + time.sleep(0.1) if terminate: exit(0) @@ -606,7 +623,11 @@ def send_image_thread(message_string, unique_topic): send_client.on_connect = on_send_connect send_client.on_publish = on_send_publish if TLS_ENABLED: - send_client.tls_set(ca_certs, certfile, keyfile) + if BROKER_ADDRESS == MOSQUITTO_BROKER_LOCAL_ADDRESS: + send_client.tls_set(ca_certs, certfile, keyfile, cert_reqs=ssl.CERT_NONE) + send_client.tls_insecure_set(True) + else: + send_client.tls_set(ca_certs, certfile, keyfile) send_client.connect(BROKER_ADDRESS, BROKER_PORT, MQTT_KEEP_ALIVE) while send_client.connected_flag == False: send_client.loop(0.1) @@ -807,7 +828,11 @@ def publisher_loop(): pub_client.on_connect = on_connect pub_client.on_subscribe = on_subscribe if TLS_ENABLED: - pub_client.tls_set(ca_certs, certfile, keyfile) + if BROKER_ADDRESS == MOSQUITTO_BROKER_LOCAL_ADDRESS: + pub_client.tls_set(ca_certs, certfile, keyfile, cert_reqs=ssl.CERT_NONE) + pub_client.tls_insecure_set(True) + else: + pub_client.tls_set(ca_certs, certfile, keyfile) pub_client.connect(BROKER_ADDRESS, BROKER_PORT, MQTT_KEEP_ALIVE) while pub_client.connected_flag == False: @@ -846,31 +871,31 @@ def publisher_loop(): # ===================================================================== if __name__ == "__main__": + print("################################################################################################################################") print("Infineon Test MQTT Publisher.") - print(" Usage: 'python publisher.py [tls] [-l] [-b ] [-k ] [-f ] [-c ]'") - print("[tls] Use TLS for connection") - print("-l Turn on extra logging") - print("-b '[a] | [amazon] | [e] | [eclipse] | [m] | [mosquitto]'") - print("-k '[CY8CKIT_062S2_43012] | [CY8CKIT_064B0S2_4343W] | [CY8CPROTO_062_4343W] | [KIT_XMC72_EVK]'") - print("-f The location of the OTA Image file to server to the device") - print("-c This will be the beginning of the topic: /") - print("Defaults: non-TLS") + print("Usage: 'python publisher.py [tls] [-l] [-b ] [-k ] [-f ]'") + print(" | [a] or [amazon] | [e] or [eclipse] | [m] or [mosquitto] | [ml] or [mosquitto_local] |") + print(" CY8CPROTO_062S2_43439 | CY8CPROTO_062_4343W | CY8CKIT_062S2_43012 | CY8CEVAL_062S2_LAI_4373M2 | CY8CEVAL_062S2_MUR_43439M2 | CY8CPROTO_062S3_4343W | KIT_XMC72_EVK_MUR_43439M2 |") + print(" The location of the OTA Image file to server to the device") + print("Defaults: ") print(" : -f " + OTA_IMAGE_FILE) - print(" : -b mosquitto ") + print(" : -b mosquitto_local ") print(" : -k " + KIT) - print(" : -c " + COMPANY_TOPIC_PREPEND) + print(" : -l turn on extra logging") + print("################################################################################################################################") last_arg = "" + OTA_IMAGE_FILE_NEW = None + for i, arg in enumerate(sys.argv): - # print(f"Argument {i:>4}: {arg}") + if arg == "-h" or arg == "--help": + sys.exit() if arg == "TLS" or arg == "tls": TLS_ENABLED = True if arg == "-l": DEBUG_LOG = 1 DEBUG_LOG_STRING = "1" if last_arg == "-f": - OTA_IMAGE_FILE = arg - if last_arg == "-c": - COMPANY_TOPIC_PREPEND = arg + OTA_IMAGE_FILE_NEW = arg if last_arg == "-b": if ((arg == "amazon") | (arg == "a")): BROKER_ADDRESS = AMAZON_BROKER_ADDRESS @@ -878,12 +903,23 @@ def publisher_loop(): BROKER_ADDRESS = ECLIPSE_BROKER_ADDRESS if ((arg == "mosquitto") | (arg == "m")): BROKER_ADDRESS = MOSQUITTO_BROKER_ADDRESS + if ((arg == "mosquitto_local") | (arg == "ml")): + BROKER_ADDRESS = MOSQUITTO_BROKER_LOCAL_ADDRESS if last_arg == "-k": KIT = arg last_arg = arg + if OTA_IMAGE_FILE_NEW == None: + OTA_IMAGE_FILE = "/" + BUILD_CONFIG + "/ota-update.bin" + if KIT.startswith("KIT_XMC7"): + OTA_IMAGE_FILE = "../build/APP_" + KIT + OTA_IMAGE_FILE + else: + OTA_IMAGE_FILE = "../build/APP_" + KIT.replace("_","-") + OTA_IMAGE_FILE + else: + OTA_IMAGE_FILE = OTA_IMAGE_FILE_NEW + print("\n") -print("Values for this run:\n") + if TLS_ENABLED: print(" Using TLS") else: @@ -894,10 +930,10 @@ def publisher_loop(): print(" extra debug : " + DEBUG_LOG_STRING) print(" company topic : " + COMPANY_TOPIC_PREPEND) -PUBLISHER_JOB_REQUEST_TOPIC = COMPANY_TOPIC_PREPEND + "/" + KIT + "/" + PUBLISHER_LISTEN_TOPIC +PUBLISHER_JOB_REQUEST_TOPIC = COMPANY_TOPIC_PREPEND + "/APP_" + KIT + "/" + PUBLISHER_LISTEN_TOPIC print("PUBLISHER_JOB_REQUEST_TOPIC : " + PUBLISHER_JOB_REQUEST_TOPIC) -PUBLISHER_DIRECT_REQUEST_TOPIC = COMPANY_TOPIC_PREPEND + "/" + KIT + "/" + PUBLISHER_DIRECT_TOPIC +PUBLISHER_DIRECT_REQUEST_TOPIC = COMPANY_TOPIC_PREPEND + "/APP_" + KIT + "/" + PUBLISHER_DIRECT_TOPIC print("PUBLISHER_DIRECT_REQUEST_TOPIC: " + PUBLISHER_DIRECT_REQUEST_TOPIC) print("\n") @@ -908,7 +944,12 @@ def publisher_loop(): # if TLS_ENABLED: BROKER_PORT = 8883 - if BROKER_ADDRESS == MOSQUITTO_BROKER_ADDRESS: + if BROKER_ADDRESS == MOSQUITTO_BROKER_LOCAL_ADDRESS: + BROKER_PORT = 8884 + ca_certs = "mosquitto_ca.crt" + certfile = "mosquitto_client.crt" + keyfile = "mosquitto_client.key" + elif BROKER_ADDRESS == MOSQUITTO_BROKER_ADDRESS: BROKER_PORT = 8884 ca_certs = "mosquitto.org.crt" certfile = "mosquitto_client.crt" diff --git a/source/cy_ota_agent.c b/source/cy_ota_agent.c index b364f59..5f7a4da 100644 --- a/source/cy_ota_agent.c +++ b/source/cy_ota_agent.c @@ -1424,7 +1424,6 @@ static cy_rslt_t cy_ota_open_filesystem(cy_ota_context_t *ctx) ctx->storage_open = 1; } - return result; } @@ -2064,6 +2063,13 @@ static void cy_ota_agent( cy_thread_arg_t arg ) cy_ota_set_last_error(ctx, CY_RSLT_SUCCESS); result = CY_RSLT_SUCCESS; } + else + { + cy_ota_log_msg(CYLF_MIDDLEWARE, CY_LOG_ERR, "OTA Agent state :%s, Data download retry count exceeded CY_OTA_MAX_DOWNLOAD_TRIES(%d) !!!", + cy_ota_get_state_string(ctx->curr_state), CY_OTA_MAX_DOWNLOAD_TRIES); + /* If Retry exceeds CY_OTA_MAX_DOWNLOAD_TRIES close the file system. */ + cy_ota_close_filesystem(ctx); + } } else if ( ( (ctx->curr_state == CY_OTA_STATE_JOB_CONNECT) || (ctx->curr_state == CY_OTA_STATE_DATA_CONNECT) || diff --git a/version.xml b/version.xml index a752d55..5585c1f 100644 --- a/version.xml +++ b/version.xml @@ -1 +1 @@ -4.3.1.1045 +4.3.2.1052