@ScruffR and I have suggested that you insert a line of code to print out the string received by the function. Doing so would greatly help with the debugging process. You could then copy the output and paste it here so we can analyze the JSON.
int Fsave1(const char *JSvalue) {
Serial.println(JSvalue);
...
JSvalue = //the print comand for this is right after, int Fsave1(const char *JSvalue) line
JSvalue = // the print comand for this is after, parser1.addString(JSvalue); line
onHour = 536882528 // incorrect datas
onMinue = 536910552
offHour = 536910552
offMinute = 134878799
@kazemzahedi, back to your issue, you should ensure that you are actually sending the JSON when you are calling the function like @ScruffR has mentioned.
Also, as a workaround for this case, you could change the if(parser1.parse()) { line to the following to not try to get the values if the length of JSValue is zero:
Passing an empty buffer to parse() isn’t really useful, but as nrobinson2000 pointed out, it really is a bug that it returns true. It should return false. The workaround he listed will work, as will version 0.1.1 that fixes this bug:
0.1.1 (2020-05-14)
Fixed a bug where calling parse() on an empty buffer returns true. It should return false. See issue #7.
@nrobinson2000 thanks everyone, I implemented @ScruffR suggestion I used Particle Console, and yes my string is empty
your test line was implemented too, It also confirms that my strig is empty
This now arises another question that even though Chrome browser says JSON string is sent properly, while I am not getting it at my end.
Do I have to correct my web app or my C code?
My web app is fairly a large one, should I send it anyway?
You will likely have to fix your web app. I assume you have managed to call the function with the API, but you are not sending your JSON payload. Could you share just the lines where you are using the API to call the function and attempting to send the JSON? (With your access token and deviceID redacted.)
I have a few example JavaScript functions for using the Particle API but they use synchronous XMLHttpRequest for simplicity. You might find them useful:
Once you've set your access token and deviceID you could call the "test1" function with the following:
If you'd like to share your web app you could create a repository or share it as a gist if you want others to have a look at it. Make sure to redact any sensitive information like access tokens or device IDs.
@nrobinson2000 and @ScruffR, thank you so much gentlemen, I managed to use @nrobinson2000
code example and got the json string to my photon. I am very happy. It is so much easier for me to learn from code examples than anything else.