bubba198 2 Posted March 8, 2015 Share Posted March 8, 2015 What's wrong with strings addition in Energia? Super basis; both SSID and PASS area #defineds previously Serial.println("AT+CWMODE=1"); String cmd = "AT+CWJAP=\""; cmd += SSID; cmd += "\",\""; cmd += PASS; cmd += "\""; Serial.println(cmd); cmd equals null???? Thanks Quote Link to post Share on other sites
spirilis 1,265 Posted March 8, 2015 Share Posted March 8, 2015 Hmm. Which board/platform are you using? Sent from my Galaxy Note II with Tapatalk 4 Quote Link to post Share on other sites
spirilis 1,265 Posted March 8, 2015 Share Posted March 8, 2015 Also where are SSID and PASS defined... Sent from my Galaxy Note II with Tapatalk 4 Quote Link to post Share on other sites
bubba198 2 Posted March 8, 2015 Author Share Posted March 8, 2015 @@spirilis Thanks for the quick reply. The code is from ubidots: http://ubidots.com/docs/devices/ESP8266.html I'm using MSP430 G2553 I'm finding that String cmd = "anything" doesn't work at all? I guess I am missing fundamentals with that? Basically String cmd = "anything" will return cmd to be null? I am puzzled?Thank you Quote Link to post Share on other sites
roadrunner84 466 Posted March 9, 2015 Share Posted March 9, 2015 A few days ago a similar issue raised with stings. Apparently, the C++ runtime cannot do free space allocations, try using c style strings instead: Serial.println("AT+CWMODE=1"); char cmd[50] = ""; // use any large enough value, but as small as possible sprintf(cmd, "AT+CWJAP=\"%s\",\"%s\"", SSID, PASS); Serial.println(cmd); Or alternatively, use multiple small print stamements: Serial.println("AT+CWMODE=1"); Serial.print("AT+CWJAP=\""); Serial.print(SSID); Serial.print("\",\""); Serial.print(PASS); Serial.println("\""); Quote Link to post Share on other sites
bubba198 2 Posted March 9, 2015 Author Share Posted March 9, 2015 @@roadrunner84 Thank you for the suggestion. I suspected something is broken. Forget my own example and problems. I discovered strange stuff. Take the sketch book examples that come with Energia. Pick the string addition example or simply use the on-line Energia tutorial: http://energia.nu/Tutorial_StringConstructors.html It would work; then simply include the SoftSerial library; I mean just include it; no calls to functions no nothing -- it breaks the example; half the code produces totally different results than when compiled without the library though in both cases no compile errors occur?? Quote Link to post Share on other sites
spirilis 1,265 Posted March 9, 2015 Share Posted March 9, 2015 My hunch is RAM overflow. String requires dynamic allocation/free'ing and if the heap is already full of stuff + stack is doing its thing, it's possible the dynamic allocations blow into the stack. Would be interesting to see if this all works properly on the F5529LP or FRAM (FR5969) LaunchPads. Quote Link to post Share on other sites
spirilis 1,265 Posted March 9, 2015 Share Posted March 9, 2015 Fwiw, back when I used the Arduino I remember the seasoned folks on the arduino.cc forums always urgently recommending that NOBODY USE String, just use C strings and the standard C-library str* functions to manipulate them since heap/memory fragmentation can occur quickly with the limited amount of SRAM on those chips (and those ATmega328P's had 2KB SRAM to work with...) Quote Link to post Share on other sites
roadrunner84 466 Posted March 10, 2015 Share Posted March 10, 2015 @@bubba198 If the inclusion of a library causes different behaviour, you can make a safe bet that there is just too few RAM left to do everything required. Your compiler wouldn't know, because String uses free space, not static or stack space. Free space (a.k.a. heap) can only be determined by the run-time (or Lint possibly), but not by the compiler. So your problems will go undetected at compile/upload time. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.