Declaring variables a quicker way

For debug logging, try something like:

error_log( var_export( $decoded, true ) );

The output will go to the PHP error log, but the location of that file will vary according to your system’s configuration.

But I think you might have a couple of other problems. Based on what you said previously, it looks like the data received in the webhook should look like:
{"input":[1, 0, 1, 1, 1, 1, 0]}
Yes?

If that’s correct, then, considering that you’re also passing true as a second parameter to json_decode(), which causes it to produce an associative array instead of an object, then your SQL insert should look more like:

$sql = "INSERT INTO `monitorvalues` (`dimp0`, `dimp1`, `dimp2`, `dimp3`, `dimp4`, `dimp5`, `dimp6` ) VALUES ('$input[0]', '$input[1]', '$input[2]', '$input[3]', '$input[4]', '$input[5]', '$input[6])";
1 Like

I have managed to rectify the problem. Thank you for your help.

Can you also post the solution for others to benefit from?

Yes not a problem. I used the explode function to separate the values by the , and put them into an array.

Scruffr, this is an excellent tutorial on coding. To revisit Ben’s original issue, sometimes his original lengthy coding can have the advantage of simplicity when re-familiariz ing months or years after the original codewriting.
Can you discuss the impact of that the advanced coding technique has on the CPU’'s interpretation of the code, run time, etc?
Thanks

2 Likes

This is hard to quantify since modern optimizers for speed may even unpack constant count loops into a bunch of hardcoded instructions which may look very much like the original code.
But even with no optimization the overhead of a for loop in comparison to multple calls of e.g. pinMode() is insignificant (2-4 clock cycles vs. several dozens per iteration).

1 Like