[SOLVED] In sensor integration error?

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 &#039;8&#039; for key &#039;data_stream_basic.PRIMARY&#039;: INSERT INTO &quot;data_stream_basic&quot; (&quot;id&quot;, &quot;timestamp&quot;, &quot;value_numerator&quot;, &quot;value_denominator&quot;) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array
(
    [:db_insert_placeholder_0] =&gt; 8
    [:db_insert_placeholder_1] =&gt; 1709555953
    [:db_insert_placeholder_2] =&gt; 80
    [:db_insert_placeholder_3] =&gt; 1
)
 in <em class="placeholder">Drupal\mysql\Driver\Database\mysql\ExceptionHandler-&gt;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-&gt;execute() (Line: 44)
Drupal\mysql\Driver\Database\mysql\Insert-&gt;execute() (Line: 487)
Drupal\data_stream\Plugin\DataStream\DataStreamType\Basic-&gt;storageSave() (Line: 428)
Drupal\data_stream\Plugin\DataStream\DataStreamType\Basic-&gt;storageSave() (Line: 152)
Drupal\farm_sensor\Controller\SensorDataController-&gt;handleAssetRequest() (Line: 77)
Drupal\farm_sensor\Controller\SensorDataController-&gt;uuid()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer-&gt;executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel-&gt;handle() (Line: 54)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap-&gt;handle() (Line: 58)
Drupal\Core\StackMiddleware\Session-&gt;handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength-&gt;handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState-&gt;handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel-&gt;handle() (Line: 704)
Drupal\Core\DrupalKernel-&gt;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

  • schannel: failed to decrypt data, need more data
    < HTTP/1.1 500 500 Service unavailable (with message)
    < Date: Mon, 04 Mar 2024 13:11:25 GMT
    < Server: Apache/2.4.41 (Ubuntu)
    < Cache-Control: must-revalidate, no-cache, private
    < Content-language: en
    < X-Content-Type-Options: nosniff
    < X-Frame-Options: SAMEORIGIN
    < Expires: Sun, 19 Nov 1978 05:00:00 GMT
    < X-Generator: Drupal 10 (https://www.drupal.org)
    < Connection: close
    < Transfer-Encoding: chunked
    < Content-Type: text/html; charset=UTF-8
    <
  • schannel: server closed the connection
    The website encountered an unexpected error. Try again later.

    Drupal\Core\Database\IntegrityConstraintViolationException: 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] => 1709557885
    [:db_insert_placeholder_2] => 786
    [:db_insert_placeholder_3] => 10
    )
    in Drupal\mysql\Driver\Database\mysql\ExceptionHandler->handleExecutionException() (line 45 of core/modules/mysql/src/Driver/Database/mysql/ExceptionHandler.php).
    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: 320)
    Drupal\data_stream\Plugin\DataStream\DataStreamType\Basic->apiPost() (Line: 266)
    Drupal\data_stream\Plugin\DataStream\DataStreamType\Basic->apiHandleRequest() (Line: 63)
    Drupal\data_stream\Controller\DataStreamController->dataStream()
    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)
    * Closing connection
  • schannel: shutting down SSL/TLS connection with farm.aatrral.org port 443
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.

ok sir, thank you.

1 Like