I wrote an ‘Auth’ library which mainly crates a 332 bytes password for MQTT connection. By now I’ve consumed 89% of flash and 71% of SRAM.
Sketch uses 28,786 bytes (89%) of program storage space. Maximum is 32,256 bytes. Global variables use 1,457 bytes (71%) of dynamic memory, leaving 591 bytes for local variables. Maximum is 2,048 bytes.
Attachment mqtt_test.ino mainly has 3 parts.
- Init Ethernet
- Generate password
- Connect to MQTT and send message
At the top of the sketch I have 3 macros for testing. Enable ETHERNET_TEST and AUTH generates right password. Enable ETHERNET_TEST and MQTT_TEST can connect to MQTT and send message successfully. However, enable ETHERNET_TEST, MQTT_TEST, and AUTH cannot work properly.
The system will hang at the stage after initializing Ethernet.
memory(start): 519 Initializing Ethernet...Connected with IP: 220.127.116.11 memory: 419
I’ve calculated the free memory, for the part of generating password normally needs 330 to 360 bytes memory. Would there be a problem if it got 419 bytes memory left at the stage of generating password?
Libraries I’ve included:
Which PubSubClient is from knolleary’s, SHA is from Cryptosuite, and Base64 is from adamvr
- Arduino UNO R3
- Ethernet shield 2
- IDE 1.7.4
Libraries I’ve used are also attached. I did my best to optimize Auth/Authentication_OneFile.cpp
No sure if there is any place can be improved…
Suggestions would be appreciated.
mqtt_test.ino (2.61 KB)
libraries.zip (347 KB)