Device not sending data to LWM2M Agent - iot

I'm having trouble with LWM2M device sending data to the IOT Agent. The device connects to the server successfully.
However, it seems the device isn't sending data to the IOT Agent, with no helpful tip, sending the command:
curl --request POST \
--header 'Content-Type: text/plain' \
--header 'Fiware-Service: workshop' \
--header 'Fiware-ServicePath: /' \
--header 'X-Auth-Token: NULL' \
--data 't|30' \
-v \
'http://localhost:4041/iot/d?k=workshop-devices&i=robot1'
It returns the message:
* About to connect() to localhost port 4041 (#0)
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 4041 (#0)
> POST /iot/d?k=workshop-devices&i=robot1 HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:4041
> Accept: */*
> Content-Type: text/plain
> Fiware-Service: workshop
> Fiware-ServicePath: /
> X-Auth-Token: NULL
> Content-Length: 4
>
* upload completely sent off: 4 out of 4 bytes
< HTTP/1.1 404 Not Found
< X-Powered-By: Express
< Fiware-Correlator: 32da2092-8032-427a-86f2-19ae81a1ab47
< Content-Security-Policy: default-src 'self'
< X-Content-Type-Options: nosniff
< Content-Type: text/html; charset=utf-8
< Content-Length: 145
< Date: Mon, 24 Sep 2018 10:30:25 GMT
< Connection: keep-alive
<
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot POST /iot/d</pre>
</body>
</html>
* Connection #0 to host localhost left intact
Not sure if anyone understands what's going here please.

Have you followed the steps of https://github.com/telefonicaid/lightweightm2m-iotagent/blob/master/docs/deviceProvisioning.md?
I ask this because using LWM2M, it is not possible to use curl commands to send observations from devices. You need to use an LWM2M client for that purpose.

Related

HTTP Request with content-length > 0 but body is empty in docker container

I am trying to run curl commands in a groovy script and containerize it using docker. The script runs a bunch of curl commands. Using the following code to execute the commands.
def process = commandArray.execute()
def out = new StringBuffer()
process.consumeProcessOutputStream(out)
if (process.isAlive()) process.waitForOrKill(240000)
Things work fine when I run locally. But When I execute the groovy script in container the response body comes as empty but the Content-Length will be more than 0.
My headers are as below(Have Replaced few content with dummy data, ex: xyz.com)
* TCP_NODELAY set
* Connected to xyz.com (10.20.30.400) port 80 (#0)
> GET /abc/xyz/type HTTP/1.1
> Host: xyz.com
> User-Agent: curl/7.68.0
> Accept: */*
>
< HTTP/1.1 200 OK
< cache-control: no-cache, private
< etag: "000000000000000000000000000000"
< x-content-type-options: nosniff
< x-xss-protection: 1; mode=block
< strict-transport-security: max-age=31536000 ; includeSubDomains
< x-frame-options: DENY
< content-type: application/json
< content-length: 72950
< date: Tue, 22 Jun 2021 06:17:09 GMT
< x-envoy-upstream-service-time: 57
< server: envoy
<
{ [15940 bytes data]
* Connection #0 to host xyz.com left intact
Although the content-length: 72950 when I print the out object, it is empty []
What might be going on here? This issue is specific to running in container
The curl command looks as below
curl -s -v -L -k -X 'GET' --cert '/tmp/groovy-generated-10305010891926264191-tmpdir/client-cert.pem' --proxy 'https://proxy.com:30000' --noproxy 'localhost,127.0.0.1' 'https://example.com/abc/xyz/type'

Unable to post telemetry data using HTTP from command line

Unable to post telemetry data using HTTP from command line, I can not get any message in my thingsboard Platform
C:\Users\Administrator>curl -v -X POST -d "{\"temperature\": 25}" http://localhost:8080/api/v1/mdULJGYox2jQmDmFbZID/telemetry --header "Content-Type:application/json"
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> POST /api/v1/mdULJGYox2jQmDmFbZID/telemetry HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.55.1
> Accept: */*
> Content-Type:application/json
> Content-Length: 19
>
* upload completely sent off: 19 out of 19 bytes
< HTTP/1.1 200
< Vary: Origin
< Vary: Access-Control-Request-Method
< Vary: Access-Control-Request-Headers
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< Content-Length: 0
< Date: Wed, 15 Jul 2020 07:36:48 GMT
<
* Connection #0 to host localhost left intact
i'm new to thingsboard. I also encountered the same issue right now. But it works when i use postman to send the same http request to a locally installed se. So maybe it gets stuck in the curl command.

What params is devise_auth_token expecting?

Devise_auth_token newbie here. I have a rails 5 api only app. I'm trying to make requests to my api using curl and I have managed to do so successfully except for when I want to sign in a user.
curl -XPOST -H 'Content-Type: application/json' -d '{ "session": { "email":"example2#gmail.com", "password": "password"}}' localhost:3000/auth/sign_in
Not sure what I am doing wrong. As I said, for some reason there is no problem when creating a user. When trying to sign in I get this error
{"errors":["Invalid login credentials. Please try again."]}
Any help is greatly appreciated, thank you.
curl -v -XPOST -H 'Content-Type: application/json' -d '{ "email":"admin#example.com", "password": "password"}' localhost:3000/auth/sign_in
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 3000 (#0)
> POST /auth/sign_in HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:3000
> Accept: */*
> Content-Type: application/json
> Content-Length: 55
>
* upload completely sent off: 55 out of 55 bytes
< HTTP/1.1 200 OK
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< Content-Type: application/json; charset=utf-8
< access-token: Bm3FaRpSAjT-EtTrj8Ucww
< token-type: Bearer
< client: 6XCiYTxcEITVRZItRKFa8w
< expiry: 1480750998
< uid: admin#example.com
< ETag: W/"be9091473a08ccf2672b9685eb25caa2"
< Cache-Control: max-age=0, private, must-revalidate
< X-Request-Id: 4996fb00-a45c-41e4-b30b-c86bc10b24d5
< X-Runtime: 0.737506
< Transfer-Encoding: chunked
<
* Connection #0 to host localhost left intact
{"data":{"id":1,"email":"admin#example.com","provider":"email","uid":"admin#example.com","name":null,"nickname":null,"image":null}}
Use -v for curl - it will give you many clues.
Comment was right - do not place login / password inside session.
Snip from TL;DR that you should read thoroughly:
The authentication headers consists of the following params: access-token, client, expire, uid
The authentication headers required for each request will be available in the response from the previous request.

Why is this refresh token request to auth.docker.io returning a 404?

I am trying to use the api documented here: https://docker.github.io/registry/spec/auth/oauth/
When I POST to the service as described in the docs, it always returns a 404.
I've tried this using my own account and also using the exact query in the documentation.
Here is an example:
[prompt]$ curl -v \
-H 'Content-Type: application/x-www-form-urlencoded' \
-X POST -d 'grant_type=password&username=johndoe&password=A3ddj3w&service=hub.docker.io&client_id=dockerengine&access_type=offline' \
https://auth.docker.io/token
* Trying 52.5.234.85...
* Connected to auth.docker.io (52.5.234.85) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
* Server certificate: *.docker.io
* Server certificate: RapidSSL SHA256 CA - G3
* Server certificate: GeoTrust Global CA
POST /token HTTP/1.1
Host: auth.docker.io
User-Agent: curl/7.43.0
Accept: /
Content-Type: application/x-www-form-urlencoded
Content-Length: 118
upload completely sent off: 118 out of 118 bytes
< HTTP/1.1 404 Not Found
< Content-Type: text/plain; charset=utf-8
< X-Content-Type-Options: nosniff
< Date: Fri, 04 Nov 2016 01:10:14 GMT
< Content-Length: 19
< Strict-Transport-Security: max-age=31536000
<
404 page not found
Connection #0 to host auth.docker.io left intact
The same response is returned when using credentials for an active account.
It seems that I should at least receive a 401 if the account not authenticated.
Is this service no longer supported?
There is a GET api that I can use to acquire a short-lived bearer token, but I need a refresh token.
That GET api is documented here: https://docs.docker.com/registry/spec/auth/jwt/
I was having the same problem. I'll put the solution first, with extra info later.
DOCKER_HUB_USERNAME=$1
DOCKER_HUB_PASSWORD=$2
DOCKER_REPO=$3
AUTH_64=$(echo -n $DOCKER_HUB_USERNAME:$DOCKER_HUB_PASSWORD | base64)
TOKEN=$(curl -s -H "Authorization: Basic $AUTH_64" \
-H 'Accept: application/json' \
"https://auth.docker.io/token?service=registry.docker.io&scope=repository:$DOCKER_REPO:pull" | jq -r .token)
curl -s -H "Authorization: Bearer $TOKEN" -H "Accept: application/json" \
"https://index.docker.io/v2/$DOCKER_REPO/tags/list" | jq -r .tags
I did some digging and found this answer which required you to use docker login, which isn't what I wanted. After looking into the docker conf file he was pulling from, I figured out the value was the base64 encoding of user:pass. So I just avoid trying to get a refresh token.
I used jq to get the json values. Here is a download link. You can retrieve them however you want. I placed the second command in as an example, although this should work with anything from the v2 API. I think you can even replace index.docker.io with any docker registry.
Oh, if you need push access be sure to change $DOCKER_REPO:pull to $DOCKER_REPO:pull,push

Curl POST request in JSON format

I'd like to send a HTTP POST request in JSON format to a specific URL using Curl in the mac terminal.
How do I specify the HTTP verb POST? What is the difference between -d and -X?
How do I specify that I'm sending my data in JSON format?
Any suggestions on how to test the request itself? I'd like to test and see exactly what JSON data is being sent across before I do my 'live' request. Can I run a Rails server on localhost and send my POST request to localhost? How can I see the JSON data?
Any examples are welcome.
Thanks!
1) If you are using the -d option to upload data, curl with automatically use POST. The -X option is used when you want to specify the method (PUT, DELETE etc) rather than getting curl to choose it for you.
echo "how are you" | curl -vvv -d#- http://localhost:8000
* About to connect() to localhost port 8000 (#0)
* Trying 127.0.0.1...
* connected
* Connected to localhost (127.0.0.1) port 8000 (#0)
> POST / HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8y zlib/1.2.5
> Host: localhost:8000
> Accept: */*
> Content-Length: 11
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 11 out of 11 bytes
< HTTP/1.1 200 OK
< Date: Sun, 03 Aug 2014 13:46:44 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
2) You can specify that you are sending your data in json format by using the Content-type header. This header can be added in curl using the -H option.
3) Yes you can setup a webserver(using python, nodejs, rails etc) that can just printout the http body once it receives it.
$ curl -d "param1=value1&param2=value2" http://example.com/posts
$ curl -i -H "Accept: application/json" -H "Content-Type: application/json" http://example.com/posts
I prefer use https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo

Resources