Argument #1 ($data) must be of type array, null given, called in /home/coconut/farmos/web/profiles/farm/modules/asset/sensor/src/Controller/SensorDataController.php on line 138
above error happened.
i just hit below request:
curl -H "Content-Type: application/json" -X POST -d "{ "timestamp": 1709551292, "NPA_first_sensor_stream": 76.5, "value2": 60 }" https://farm.aatrral.org/asset/56547db8-dca7-41f5-b77b-46cdbd5b52ba/data/basic?private_key=a7ab1ccf05656283de2358dc714c7c86
Full error:
C:\Users\ADMIN>curl -H “Content-Type: application/json” -X POST -d “{ “timestamp”: 1709551292, “NPA_first_sensor_stream”: 76.5, “value2”: 60 }” https://farm.aatrral.org/asset/56547db8-dca7-41f5-b77b-46cdbd5b52ba/data/basic?private_key=a7ab1ccf05656283de2358dc714c7c86
The website encountered an unexpected error. Try again later.
TypeError: Drupal\farm_sensor\Controller\SensorDataController::getUniqueNamedValues(): Argument #1 ($data) must be of type array, null given, called in /home/coconut/farmos/web/profiles/farm/modules/asset/sensor/src/Controller/SensorDataController.php on line 138 in Drupal\farm_sensor\Controller\SensorDataController->getUniqueNamedValues() (line 186 of profiles/farm/modules/asset/sensor/src/Controller/SensorDataController.php).
Drupal\farm_sensor\Controller\SensorDataController->handleAssetRequest() (Line: 77)
Drupal\farm_sensor\Controller\SensorDataController->uuid()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 54)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
Drupal\Core\DrupalKernel->handle() (Line: 19)
1 Like
curl -v -X POST -d @test.json https://farm.aatrral.org/asset/56547db8-dca7-41f5-b77b-46cdbd5b52ba/data/basic?private_key=a7ab1ccf05656283de2358dc714c7c86 --header "Content-Type:application/json"
test.json
{"timestamp": 1709554091, "NPA_first_sensor_stream": 76.5, "value2": 60 }
it’s worked one time.
1 Like
@aathi179 Glad you figured it out!
1 Like
but, issue not solved. when i wan to try to post one more time it showing below error.
The website encountered an unexpected error. Try again later.<br><br><em class="placeholder">Drupal\Core\Database\IntegrityConstraintViolationException</em>: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '8' for key 'data_stream_basic.PRIMARY': INSERT INTO "data_stream_basic" ("id", "timestamp", "value_numerator", "value_denominator") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array
(
[:db_insert_placeholder_0] => 8
[:db_insert_placeholder_1] => 1709555953
[:db_insert_placeholder_2] => 80
[:db_insert_placeholder_3] => 1
)
in <em class="placeholder">Drupal\mysql\Driver\Database\mysql\ExceptionHandler->handleExecutionException()</em> (line <em class="placeholder">45</em> of <em class="placeholder">core/modules/mysql/src/Driver/Database/mysql/ExceptionHandler.php</em>). <pre class="backtrace">Drupal\Core\Database\StatementWrapperIterator->execute() (Line: 44)
Drupal\mysql\Driver\Database\mysql\Insert->execute() (Line: 487)
Drupal\data_stream\Plugin\DataStream\DataStreamType\Basic->storageSave() (Line: 428)
Drupal\data_stream\Plugin\DataStream\DataStreamType\Basic->storageSave() (Line: 152)
Drupal\farm_sensor\Controller\SensorDataController->handleAssetRequest() (Line: 77)
Drupal\farm_sensor\Controller\SensorDataController->uuid()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 54)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
Drupal\Core\DrupalKernel->handle() (Line: 19)
</pre>* Closing connection
* schannel: shutting down SSL/TLS connection with farm.aatrral.org port 443
1 Like
thank you for your encourage. it’s inspiring me to work more.
1 Like
@aathi179 Oh I see…
I think it is because you’re posting the same timestamp and name combination twice.
If you remove the timestamp
from your JSON it should work. The timestamp will be set automatically by the server, so you don’t need to include it in your JSON unless you need to set it to something different than the current time.
sir, i tried without timestamp also not worked.
{"temperature": 78.6 }
error:
Note: Unnecessary use of -X or --request, POST is already inferred.
- Trying 103.86.177.243:443…
- Connected to farm.aatrral.org (103.86.177.243) port 443
- schannel: disabled automatic use of client certificate
- ALPN: curl offers http/1.1
- ALPN: server accepted http/1.1
- using HTTP/1.1
POST /api/data_stream/044c83ce-ad51-499a-bb7c-ed0eb7809999/data?private_key=fa31b91192f55a3029d2a9bda05d7429 HTTP/1.1
Host: farm.aatrral.org
User-Agent: curl/8.4.0
Accept: /
Content-Type:application/json
Content-Length: 23
1 Like
its resolved. that’s my mistake. i just removed primary key integrity from data_stream_basic
table.
when i was checked status report it shown as primary key error data_stream_basic
table then, i was added primary for this table by manual.
@aathi179 Glad it’s resolved!
But NEVER make manual modifications to farmOS database tables/schemas! They are managed by Drupal’s ORM, so you run the risk of creating bugs/issues if you modify them manually.