my code don’t work!!! any help plz !!!
<?php
require 'vendor/autoload.php';
$api = new Ubidots\ApiClient($apikey="xxxxxxxx");
$my_variable = $api->get_variable('xxxxxx');
$new_value = $my_variable->save_value( array('value'=>10) );
?>
Could you please add more information about the error you’re having?
Are you receiving any error message or is not sending the value to the variable?
Hi Mr. juanda95. I think the code need include the libraries. Do know know how to include them. Can you show me, I am a new member of php.
Greetings, you should install the library using composer and then to include it inside your script with the keyword “require”, please refer to the step by step tutorial at our repository.
Regards
1 Like
Can you show me why the error was?
I use the same code on php local in my laptop with xampp is Ok, however, I got errors when I try on hosting.
Here this is my picture of both cases
Case 1: on xampp
Case 2: on hosting
Here is my code
<?php
require 'vendor/autoload.php';
$apikey="35a1ad885716c6b788431a8fb34a6b988d1db22a";
$ledSwitch = "590aaa8f7625421b6afbb5bc";
$ledRed = "590aaac47625421b693cf329";
$ledBlue = "590aaab77625421b693cf217";
$ppmCtlSignal = "590aa9af7625421b6bf9a991";
$ppmIdeal = "590aa6ec7625421b693ca527";
$ppmInit = "590aa67a7625421b6cfa5fd7";
$ppmMax = "590aa60a7625421b693c92cc";
$ppmMin = "590aa60c7625421b680ec96b";
$sprayBlockTime = "5920457a762542541c769ad3";
$spraySwitch = "590ac1627625421b6afd832a";
$tempIdeal = "590aab277625421b693cfac8";
$tempMax = "590aab1c7625421b6cfabacd";
$api = new Ubidots\ApiClient($apikey);
//Led
$connectionLedSwitch = $api->get_variable($ledSwitch);
$dataLedSwitch = $connectionLedSwitch->get_values(1);
$data = $dataLedSwitch[0];
echo $data['value'];
echo "\n";
$connectionRedLed = $api->get_variable($ledRed);
$dataRedLed = $connectionRedLed->get_values(1);
$data = $dataRedLed[0];
echo $data['value'];
echo "\n";
$connectionBlueLed = $api->get_variable($ledBlue);
$dataBlueLed = $connectionBlueLed->get_values(1);
$data = $dataBlueLed[0];
echo $data['value'];
echo "\n";
//PPM
$api2 = new Ubidots\ApiClient($apikey);
$connectionppmCtlSignal = $api2->get_variable($ppmCtlSignal);
$datappmCtlSignal = $connectionppmCtlSignal->get_values(1);
$data = $datappmCtlSignal[0];
echo $data['value'];
echo "\n";
$connectionppmIdeal = $api->get_variable($ppmIdeal);
$datappmIdeal = $connectionppmIdeal->get_values(1);
$data = $datappmIdeal[0];
echo $data['value'];
echo "\n";
$connectionppmInit = $api->get_variable($ppmInit);
$datappmInit = $connectionppmInit->get_values(1);
$data = $datappmInit[0];
echo $data['value'];
echo "\n";
$connectionppmMax = $api->get_variable($ppmMax);
$datappmMax = $connectionppmMax->get_values(1);
$data = $datappmMax[0];
echo $data['value'];
echo "\n";
$connectionppmMin = $api->get_variable($ppmMin);
$datappmMin = $connectionppmMin->get_values(1);
$data = $datappmMin[0];
echo $data['value'];
echo "\n";
//Spray
$connectionsprayBlockTime = $api->get_variable($sprayBlockTime);
$datasprayBlockTime = $connectionsprayBlockTime->get_values(1);
$data = $datasprayBlockTime[0];
echo $data['value'];
echo "\n";
$connectionspraySwitch = $api->get_variable($spraySwitch);
$dataspraySwitch = $connectionspraySwitch->get_values(1);
$data = $dataspraySwitch[0];
echo $data['value'];
echo "\n";
//Temp
$connectiontempIdeal = $api->get_variable($tempIdeal);
$datatempIdeal = $connectiontempIdeal->get_values(1);
$data = $datatempIdeal[0];
echo $data['value'];
echo "\n";
$connectiontempMax = $api->get_variable($tempMax);
$datatempMax = $connectiontempMax->get_values(1);
$data = $datatempMax[0];
echo $data['value'];
?>
Can you explain? I don’t understand. Could you give me som advice, please?
Thanks
Hello @simcrop,
I see that at the beginning you retrieve properly your data (1,60,0), what you see are warnings messages but not errors, maybe they are not disabled by default inside your hosting. You can disable them using this flag error_reporting(0);
.
Regards
1 Like
Hello, @jotathebest
I look forward to retrieve (1,60,0,0,770,0,1260,280,10,0,24,28).
I do not understand why, so I need to find someone to ask.
Thanks.
Did you try adding the error_reporting(0);
line at the beginning of your code?
As @jotathebest said, it looks that your code is successfully retrieving the 1, 60 and 0 values; and then showing a lot of warnings which are dismissed with the line above in your code.
Regards
1 Like