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
Create a shared variable to share current progress of EV charging.
After each poll for ADC data, also publish the progress percentage
on relevant topic via MQTT.

Signed-off-by: Divyansh Mittal <[email protected]>
  • Loading branch information
Divyansh Mittal committed Jan 22, 2025
1 parent ddec016 commit 221b898
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion demos/high_res/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static lv_demo_high_res_api_t * api_hmi;
static struct mosquitto *mosq;
extern int back_pressed_adc;
void publish_sensor_data(float);
extern int ev_charge;

/**
* enum autochan - state for the automatic channel enabling mechanism
Expand Down Expand Up @@ -102,7 +103,13 @@ 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));
}
}

snprintf(payload, sizeof(payload), "%d", ev_charge);
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
*********************/
int ev_charge = 0;

/**********************
* 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);
ev_charge = 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 221b898

Please sign in to comment.