Comments (2)
When passing char arrays variables, such as in your code snippet above, HomeSpan retains the pointer and does not make a new copy of the string. This saves a lot of space, especially since in most use cases the strings are static. However, it is still possible to pass a dynamic string, as long as the pointer to the memory does not go out of scope leaving the memory free for other uses.
In your snippet above, is name[64] a local variable defined within a function? If so, as soon as the function returns, the memory associated with name (which is likely on the stack) will be reused and overwritten by other processes, resulting in what you are seeing.
The solution is to assign some permanent storage to name - this can be done by:
- creating name as a global variable (not the best solution in large-scale programming, but fine for a short sketch), or
- using "new" to allocate memory with a dynamic pointer so the memory is retained even after the pointer to it goes out of scope, or
- declaring name as an object variable as part of a child class containing all the logic and parameters of a HomeSpan Service.
An example of using the first method can be found in the ProgrammableHub Project.
from homespan.
Thanks for the scopes explanation, moving the variable into a global scope works.
from homespan.
Related Issues (20)
- Pixel issue. HOT 2
- Corrupted display name when passing c_str() to begin() HOT 7
- motorized window accessory crashes early?
- SpanPoint not able to send RGB values HOT 1
- Homespan not infomation wifi conect HOT 2
- Wifi connection loss (possible memory leak?) HOT 25
- Schedule Reboot HOT 2
- SRP Proof Verification Failed HOT 2
- HomeSpan not compatible with Board esp32 from espressif HOT 3
- Device not reachable after esp32
- Send push notification to phone HOT 2
- Trigger Rule 'singleTime > longTime = ALWAYS LONG' not fulfilled HOT 11
- Trouble using the television speaker service HOT 5
- "no response" - how to debug? HOT 5
- Some examples go into reboot (e.g. example 05-WorkingLED) 🥹 HOT 3
- NeoPixel Led Strip not showing colours properly HOT 3
- ESP32 Arduino Smart Home Project With HomeSpan(HomeKit protocol) VS. MATTER protocol HOT 4
- Not working when ESP32 is external powered HOT 1
- Add support for Stateful Programmable Switch HOT 16
- Apple Home left device turned on after device reconnect HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from homespan.