mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 00:55:52 +03:00
[GH-ISSUE #1395] Store the value of mqtt server address(pubsubclient) from custom parameter and reuse it dynamically #1195
Labels
No labels
📶 WiFi
🕸️ HTTP
Branch
DEV Help Wanted
Discussion
Documentation
ESP32
Example
Good First Issue
Hotfix
In Progress
Incomplete
Needs Feeback
Priority
QA
Question
Task
Upstream/Dependancy
bug
duplicate
enhancement
invalid
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/WiFiManager#1195
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @shariq-azim on GitHub (Apr 15, 2022).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1395
Hardware
WiFimanager Branch/Release: Master
Esp32
Hardware: ESP-12e, esp01, esp25
Core Version: 2.4.0, staging
Description
I am trying to set the default value in the custom parameter first, but if there is a change of value i am trying to copy and update another variable that can be re-used as the mqtt server address. So that if the connection is lost it will try to connect again with the last known value. The following code runs one and connects properly during setup but if the connection is lost with MQTT server it wont connect as it would now have garbage value in it.
The obvious reason is because the previous value of the pointer is lost after the setup function exists.
I have tried so many variations but it is not working ,and unfortunately, the solutions in internet is mostly theory and not the code. Thus, i am reaching for the experts to help. Unfortunately, the solutions in internet is mostly theory and not the code.
Please help retrieve the value from a different function.
Version :2.03-alpha, 2.0.11 beta
Additional libraries:
Pubsubclient
Sketch
Debug Messages
Additional note if i do strcpy(mqttServer , (char*)custom_mqtt_server.getValue()); instead of mqttServer = (char*)custom_mqtt_server.getValue(); //because datatype of mqttServer is char* it will go into panic mode
@tablatronix commented on GitHub (Apr 15, 2022):
hmm would think you would have to use a global char[] array and either set its size ahead of time, or dynamically allocate it , or just use a Strings
@shariq-azim commented on GitHub (Apr 15, 2022):
Good day to you.
I dont think pubsubclient.setserver accepts either char[] or string as an input parameter?
@shariq-azim commented on GitHub (Apr 17, 2022):
hello @tablatronix , i was just wondering if it is possible to set the value into a global variable from custom_mqtt_server.getValue() so that it can be used at later point? the step you provided earlier somehow didnt work for me..
@tablatronix commented on GitHub (Apr 17, 2022):
you can do something like the example
char mqtt_server[40];
strcpy(mqtt_server, custom_mqtt_server.getValue());
@shariq-azim commented on GitHub (Apr 19, 2022):
Thank you .it worked