bblanchon / ArduinoJson

📟 JSON library for Arduino and embedded C++. Simple and efficient.
https://arduinojson.org
MIT License
6.69k stars 1.12k forks source link

ESP32 SPIFFS load radio stations example cause WDT reboot. #1445

Closed nodoubtman closed 3 years ago

nodoubtman commented 3 years ago

Hello.. I'm using ESP32, i need to take the radio info and put it into a char array, here's my code:

include

include

include

struct ConfigRadioMtl { char postesChars[150]; }; ConfigRadioMtl configRadioMtl[50];

Here's the json buffer: { "MAX_STATIONS": 50, "station1": "https://cogecomedia.leanstream.co/CKACAM-MP3 # CKAC 730 CIRCULATION", "station2": "http://icecast-cklx.rncm.ca/cklx.mp3 # 91.9 SPORTS", "station3": "https://cogecomedia.leanstream.co/CKBEFM-MP3 # The BEAT 92.5", "station4": "https://cogecomedia.leanstream.co/CKOIFM-MP3 # CKOI 96.9", "station5": "https://cogecomedia.leanstream.co/CHMPFM-MP3? # 98,5", "station6": "https://cogecomedia.leanstream.co/CFGLFM-MP3 # RYTHME FM 105,7", "station7": "https://playerservices.streamtheworld.com/api/livestream-redirect/CHOMFMAAC.aac # CHOM FM", "station8": "http://144.217.180.30:8111/ # WAVE-80", "station9": "https://playerservices.streamtheworld.com/api/livestream-redirect/CITEFMAAC_SC # ROUGE-FM", "station10": "http://cbcmp3.ic.llnwd.net/stream/cbcmp3_M-7QMTL0_MTL # ICI-MUSIQUE", "station11": "https://igor.torontocast.com:1945/stream # AMERICAN-ROOTS", "station12": "http://streamer3.clubbingstation.com/Clubbing-Station-Eu-aac # CLUBBING-STATION", "station13": "https://playerservices.streamtheworld.com/api/livestream-redirect/CJADAMAAC.aac # CJAD", "station14": "http://listen.classichits109.com:6980/;stream.nsv # CLASSIC HITS 109 - The 70s", "station15": "https://playerservices.streamtheworld.com/api/livestream-redirect/QUB_RADIOAAC.aac # QUB", "station16": "https://playerservices.streamtheworld.com/api/livestream-redirect/CKGMAMAAC.aac # TSN 690", "station17": "https://vm.motionfm.com/motionone_free # DEEP MOTION", "station18": "http://streams.1radio.ca:8059/live # The Lounge Sound – 1Radio.ca", "station19": "https://stream.statsradio.com:8092/stream # K103.7 FM – CKRK", "station20": "http://cristina.torontocast.com:8007/mp3-320 # JB Radio-2", "station21": "http://ibiza.broadstreamer.com:8000/; # Italian Graffiati", "station22": "https://443-1.reliastream.com/37/stream # Jammin Vibez Dancehall", "station23": "http://144.217.180.30:8166/stream # Hard Rock Dinosaur-The ZED", "station24": "http://kos.broadstreamer.com:8700/; # Radio Skipper", "station25": "http://149.56.147.197:9675/stream # Le Rapologue Radio", "station26": "http://128mp3.howlincountry.com/ # Howlin' Country", "station27": "https://hitsmusicradio.out.airtime.pro/hitsmusicradio_a # Hits Music Radio", "station28": "http://hazel.torontocast.com:1295/stream # 2ks Dance Radio", "station29": "https://jenny.torontocast.com:8172/stream # Birch Street Radio", "station30": "http://stream03.ustream.ca/cism128.mp3 # CISM", "station31": "https://icecast.ckut.ca/903fm-128-stereo # CKUT 25", "station32": "https://listen.jetstreamradio.com:8000/autodj # JetStream Radio", "station33": "http://199.195.194.140:8034/stream # Montana QC", "station34": "https://ithaca.cdnstream.com/1697_192 # Today's Office Mix Radio", "station35": "http://cristina.torontocast.com:8111/; # Radio Khatru", "station36": "http://a1team.net:8128/;.mp3 # La Radio Gospel", "station37": "http://104fm.ca:8024/;stream.nsv # 104 FM Only Rock", "station38": "http://larry.torontocast.com:1820/stream # Beach Chill-out Radio", "station39": "http://dj.mediastreaming.it:7018/; # Radio Naples", "station40": "http://stream02.ustream.ca:8000/cfim128.mp3 # CFIM", "station41": "http://174.142.215.249:8880/;audio.mp3 # CNV Radio Numérique", "station42": "https://stream.zeno.fm/8482yksb4y5tv # La Fiesta Latina Fm", "station43": "http://janus.cdnstream.com:5173/stream # Teerex Radio Teerex", "station44": "https://jenny.torontocast.com:2000/stream/CottageRadio # Cottage Radio", "station45": "https://stream.zeno.fm/kvtau8d18qruv # World Hits", "station46": "http://94.23.26.193:9011/stream # ProgCore Radio", "station47": "https://dionysos.audio.imixxradio.com/live # Imixx Radio", "station48": "https://stream.zeno.fm/fpka0zfm1qzuv # Radio Impact", "station49": "https://www.radioking.com/play/radio-classique/271810 # RADIO CLASSIQUE MONTREAL", "station50": "https://streamingv2.shoutcast.com/radiovm-cira-fm # RADIO VILLE MARIE" }

// ARDUINOJSON 6 // load config from json RADIO MTL bool loadConfigJsonRadioMTL() { Serial.println(F("---------------------------")); Serial.println(F("- LOADING CONFIG JSON MTL -")); Serial.println(F("---------------------------"));

File configFile = SPIFFS.open("/RADIO_MTL_ONLINE.txt" "r"); if (!configFile) { Serial.println(F("Failed to open config file")); return false; }

Serial.println(configFile.size());

size_t size = configFile.size(); if (size > 500000) { Serial.println("Config file size is too large"); return false; } else { Serial.println("Config File Size: " + String(size)); }

// Allocate a buffer to store contents of the file. std::unique_ptr<char[]> buf(new char[size]);

// We don't use String here because ArduinoJson library requires the input // buffer to be mutable. If you don't use ArduinoJson, you may as well // use configFile.readString instead. configFile.readBytes(buf.get(), size);

// 4500 StaticJsonDocument<4500> doc; DeserializationError err = deserializeJson(doc, buf.get()); if (err) { Serial.println(err.c_str()); return false; } else { Serial.println(F("deserializeJson() OK! :o)")); }

int max_postes_radio_MTL = doc["MAX_STATIONS"]; Serial.println(max_postes_radio_MTL);

for (int i = 0; i < max_postes_radio_MTL ; i++) { String stationX = "station"; stationX += String(i + 1);

char bufferChars[stationX.length() + 1];
stationX.toCharArray( bufferChars, sizeof(bufferChars) );
strncpy(configRadioMtl[i].postesChars, doc[bufferChars], sizeof(configRadioMtl[i].postesChars));
yield();

////////////////////////////////////////////////////////////////////
Serial.println(configRadioMtl[i].postesChars);
////////////////////////////////////////////////////////////////////

yield(); }

// CRASH After the last item :-( configFile.close();

doc.clear();

return true; }

Thank you very much..

bblanchon commented 3 years ago

Hi,

It looks like a stack corruption. Please switch to a DynamicJsonDocument.

See also:

Best regards, Benoit