Send Json from Cloud to Photon

@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);
...

Yes gentlemen, here is the output

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

Nothing is printed for JSvalue as you see.
Thanks

Then how are you calling that function?
If you don’t see any contents in JSvalue you most likely have not sent any when calling the function.

For testing you can use console.particle.io/devices to call a function with parameters.

1 Like

@kazemzahedi I think you have discovered a potential bug with the JsonParserGeneratorRK library. I have submitted an issue.

@rickkas7 Have you seen this behavior before?


@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:

if(strlen(JSvalue) != 0 && parser1.parse()) {
1 Like

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.

2 Likes

@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:

callFunction("test1", '{"onH":1,"onM":35,"offH":2,"offM":55}') 

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.

I actually suggested to use cosole for sending the call to your device to check whether the C++ code is working as expected.

However, using it to check what is sent by your web app is also of some use.

Alternatively you can use CLI particle <yourDeviceName> call test1 '{"onH":8,"onM":0,"offH":10,"offM":0}' too.

1 Like

@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.

2 Likes