Websocket Toggle Button Refresh Problem #3257
Replies: 1 comment 2 replies
-
This is Mongoose repo. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I am new at Mongoose WS. I am trying to read energies and broadcast from a web server. I got 2 GPIO defined as relay1 and relay2.
Relay1 is changing from my custom logic (it is like read-only), i am reading GPIO's state before sending with web socket.
I am sending values periodically (1sec) with web sockets. All values coming true, graph refreshing, energy values changing. But Relay toggle buttons not changing the states. Other structs, API variables, UI elements reacts periodically but Toggle button is not. When I refresh page or change the state of other relay from web server, status is changing. You can see my web socket packages on inspector.
Couldn't solve this problem, I want to get yours opinions or solutions.
I've added my C codes and HTML file below this line.
`void websocket_update(struct mg_connection *c) {
uint32_t power_capacity;
struct analyzer_settings analyzer_settings;
glue_get_analyzer_settings(&analyzer_settings);
set_total_power = analyzer_settings.total_power_set;
analyzer_settings.total_power_limit = set_total_power;
power_capacity = (power.active_total_power / set_total_power)*100;
glue_set_analyzer_settings(&analyzer_settings);
struct relays relay_data;
glue_get_relays(&relay_data);
// Combine ALL data into ONE JSON object and send it in ONE message
mg_ws_printf(c, WEBSOCKET_OP_TEXT,
"{"
""voltage_l1": %.1f, "voltage_l2": %.1f, "voltage_l3": %.1f,"
""current_l1": %.1f, "current_l2": %.1f, "current_l3": %.1f,"
""power_l1": %.1f, "power_l2": %.1f, "power_l3": %.1f, "total_power": %.1f,"
""total_power_limit": %u, "power_percentage": %u,"
""relay1": %s, "relay2": %s"
"}",
voltage.ph1, voltage.ph2, voltage.ph3,
current.ph1, current.ph2, current.ph3,
power.active_power_ph1, power.active_power_ph2, power.active_power_ph3, power.active_total_power,
set_total_power, power_capacity,
relay_data.relay1 ? "true" : "false",
relay_data.relay2 ? "true" : "false"
);
}`
192.168.1.108.html
Thanks already.
Beta Was this translation helpful? Give feedback.
All reactions