Skip to content

Commit

Permalink
demos/high_res: Add HMI evCharge data publish through MQTT
Browse files Browse the repository at this point in the history
On each callback of change in ev charging progress, call publish
function to transmit message on relevant topic via MQTT.

Signed-off-by: Divyansh Mittal <[email protected]>
  • Loading branch information
Divyansh Mittal committed Jan 24, 2025
1 parent 067c5a3 commit f526522
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
29 changes: 28 additions & 1 deletion demos/high_res/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,34 @@ void publish_sensor_data(float temp)
rc = mosquitto_publish(mosq, NULL, "SmartHome/temp", strlen(payload), payload, 1, false);
if(rc != MOSQ_ERR_SUCCESS){
fprintf(stderr, "Error publishing: %s\n", mosquitto_strerror(rc));
}
}
}

void publish_evCharge_data(int ev_charge)
{
if(!flag_is_connected){
return;
}
char payload[20];
int rc;

/* Print it to a string for easy human reading - payload format is highly
* application dependent. */
snprintf(payload, sizeof(payload), "%d", ev_charge);

/* Publish the message
* mosq - our client instance
* *mid = NULL - we don't want to know what the message id for this message is
* topic = "example/temperature" - the topic on which this message will be published
* payloadlen = strlen(payload) - the length of our payload in bytes
* payload - the actual payload
* qos = 1 - publish with QoS 1 for this example
* retain = false - do not use the retained message feature for this message
*/
rc = mosquitto_publish(mosq, NULL, "SmartHome/evCharge", strlen(payload), payload, 1, false);
if(rc != MOSQ_ERR_SUCCESS){
fprintf(stderr, "Error publishing: %s\n", mosquitto_strerror(rc));
}
}

int mqtt_temp_pub_init(){
Expand Down
6 changes: 6 additions & 0 deletions demos/high_res/lv_demo_high_res_app_ev_charging.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
* DEFINES
*********************/

/*********************
* GLOBAL VARIABLE
*********************/
extern void publish_evCharge_data(int);

/**********************
* TYPEDEFS
**********************/
Expand Down Expand Up @@ -210,6 +215,7 @@ static void anim_exec_cb(void * var, int32_t v)
lv_demo_high_res_ctx_t * c = lv_obj_get_user_data(base_obj);

lv_subject_set_int(&c->ev_charging_progress, v);
publish_evCharge_data(lv_map(lv_subject_get_int(&c->ev_charging_progress), 0, EV_CHARGING_RANGE_END, 0, 100));

if(c->ev_charging_bg_cont) {
anim_state_t * anim_state = lv_obj_get_user_data(c->ev_charging_bg_cont);
Expand Down

0 comments on commit f526522

Please sign in to comment.