Skip to content

Commit

Permalink
Upload ota-update 4.3.2.1052 [2846]
Browse files Browse the repository at this point in the history
  • Loading branch information
gitlab-runner committed Nov 4, 2024
1 parent b650b09 commit d5871f8
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 42 deletions.
5 changes: 5 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions scripts/WiFi_Ethernet/ota_update.json
Original file line number Diff line number Diff line change
@@ -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"
}
111 changes: 76 additions & 35 deletions scripts/WiFi_Ethernet/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -846,44 +871,55 @@ def publisher_loop():
# =====================================================================

if __name__ == "__main__":
print("################################################################################################################################")
print("Infineon Test MQTT Publisher.")
print(" Usage: 'python publisher.py [tls] [-l] [-b <broker>] [-k <kit>] [-f <filepath>] [-c <company_topic>]'")
print("[tls] Use TLS for connection")
print("-l Turn on extra logging")
print("-b <broker> '[a] | [amazon] | [e] | [eclipse] | [m] | [mosquitto]'")
print("-k <kit> '[CY8CKIT_062S2_43012] | [CY8CKIT_064B0S2_4343W] | [CY8CPROTO_062_4343W] | [KIT_XMC72_EVK]'")
print("-f <filepath> The location of the OTA Image file to server to the device")
print("-c <company_topic> This will be the beginning of the topic: <company_topic>/")
print("Defaults: non-TLS")
print("Usage: 'python publisher.py [tls] [-l] [-b <broker>] [-k <kit>] [-f <filepath>]'")
print("<broker> | [a] or [amazon] | [e] or [eclipse] | [m] or [mosquitto] | [ml] or [mosquitto_local] |")
print("<kit> 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("<filepath> The location of the OTA Image file to server to the device")
print("Defaults: <non-TLS>")
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
if ((arg == "eclipse") | (arg == "e")):
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:
Expand All @@ -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")

Expand All @@ -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"
Expand Down
8 changes: 7 additions & 1 deletion source/cy_ota_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,6 @@ static cy_rslt_t cy_ota_open_filesystem(cy_ota_context_t *ctx)
ctx->storage_open = 1;
}


return result;
}

Expand Down Expand Up @@ -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) ||
Expand Down
2 changes: 1 addition & 1 deletion version.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<version>4.3.1.1045</version>
<version>4.3.2.1052</version>

0 comments on commit d5871f8

Please sign in to comment.