I am using WSO2 IOT server with raspberrypi 3. I am in the beginning level. I was able to switch on/off the LED bulb which is connected to raspberrypi with this command.
curl -k -X POST "https://172.16.13.86:8243/raspberrypi/1.0.0/device/us310v497by0/bulb?state=on" -H "accept: application/json" -H "Authorization: Bearer 739e2223-62b6-3a24-890f-5b6e610ed6d2"
Now I want to get the current temperature which is detected by the dht11 sensor. I want to know a same type of command which I used for switch on/off the LED bulb. Can anyone help me please?
Please try:
curl -X GET --header 'Accept: application/json' 'https://ServerIP:9443/api/device-mgt/v1.0/events/last-known/deviceType/deviceId' -H "Authorization: Bearer token"
Related
I am using WSO2 IOT server, RaspberryPi 3 device with LED and DTH11 sensor. I can manage LED with console.
What I am trying to do is turn it On and Off with my mobile application. So, I want to know how can I send the HTTP request to the API and the request also. The server is running in localhost. Can anyone help me?
This is the command I used:
curl -k -X POST https://172.16.13.86:8243/api/device-mgt/v1.0/devices/raspberrypi/operations
-H 'accept: application/json' -H 'authorization: Bearer a7a156d7-0393-3350-8b9b-0ac956723440'
-H 'content-type: application/json' -d '{"deviceIdentifiers":[r1lovwmwg113],
"operation":{"code":"bulb","type":"CONFIG", "payLoad":"state:ON"}}'```
And this is the reply:
{"activityId":"ACTIVITY_36492","code":"bulb","type":"CONFIG","createdTimeStamp":"Fri
Dec 21 11:38:20 IST
2018","activityStatus":[{"deviceIdentifier":{"id":"r1lovwmwg113","type":"raspberrypi"},"status":"PENDING"}]}
I have followed the instructions from https://github.com/spring-cloud-services-samples/cook and managed to install and run Config Server in PCF environment (SERVICE: Config Server, PLAN: standard).
I'm now trying to hit /encrypt endpoint of the p-config-server service, in order to encrypt new value. I'm following the instructions at http://docs.run.pivotal.io/spring-cloud-services/config-server/configuring-with-git.html#encryption-and-encrypted-values:
TOKEN=$(curl -k ACCESS_TOKEN_URI -u CLIENT_ID:CLIENT_SECRET -d
grant_type=client_credentials | jq -r .access_token); curl -k -H
"Authorization: bearer $TOKEN" -H "Accept: application/json"
URI/encrypt -d 'VALUE'
...but I always get:
{
"error": "access_denied",
"error_description": "Access is denied"
}
On the other side, if I try to get standard endpoint, to get config for an app, I'm able to retrieve JSON containing app properties. E.g.
TOKEN=$(curl -k ACCESS_TOKEN_URI -u CLIENT_ID:CLIENT_SECRET -d
grant_type=client_credentials | jq -r .access_token); curl -k -H
"Authorization: bearer $TOKEN" -H "Accept: application/json"
URI/my-app/default
... gives result like:
{"name":"my-app","profiles":["default"],"label":null,"version":"bb6e64592ced731ebba272430291a595e0f14a77","state":null,"propertySources":[{"name":"https://github.com/some-user/config/my-app.yml","source":{"my-property.name":"Test123"}}]}
Any idea why I can not access /encrypt endpoint?
Thank you.
Btw, I'm executing the command in CentOS Linux release 7.4.1708, with installed jq (command-line JSON processor).
I've got the answer from CloundFoundry IT support. In my CF environment, "encrypt" endpoint should have a trailing slash (/). So it should be ...URI/encrypt/ -d 'VALUE'. Maybe it helps someone.
One more hint I've got: There is a CF CLI plugin for the Spring-Cloud-Services which you could use for convenience.
https://github.com/pivotal-cf/spring-cloud-services-cli-plugin
cf install-plugin -r CF-Community "Spring Cloud Services"
cf help config-server-encrypt-value
Hi Actually you need to hit cf env command first and take note of configuration values from that which for sample looks like below:
{
"VCAP_SERVICES": {
"p-config-server": [
{
"credentials": {
"access_token_uri": "https://p-spring-cloud-services.uaa.cf.wise.com/oauth/token",
"client_id": "p-config-server-876cd13b-1564-4a9a-9d44-c7c8a6257b73",
"client_secret": "rU7dMUw6bQjR",
"uri": "https://config-86b38ce0-eed8-4c01-adb4-1a651a6178e2.apps.wise.com"
},
[...]
and then use those values in your curl bash script. for example
TOKEN=$(curl -k https://config-86b38ce0-eed8-4c01-adb4-1a651a6178e2.apps.wise.com -u p-config-server-876cd13b-1564-4a9a-9d44-c7c8a6257b73:rU7dMUw6bQjR -d
grant_type=client_credentials | jq -r .access_token); curl -k -H
"Authorization: bearer $TOKEN" -H "Accept: application/json"
URI/ENDPOINT | jq
Basically following values are required:
ACCESS_TOKEN_URI with the value of credentials.access_token_uri
CLIENT_ID with the value of credentials.client_id
CLIENT_SECRET with the value of credentials.client_secret
URI with the value of credentials.uri
Replace ENDPOINT with the relevant endpoint:
application/profile to retrieve configuration from a Config Server service instance
eureka/apps to retrieve the registry from a Service Registry service instance
Then I think you will no more get access denied response.
I have web service running on server URL-http://localhost:8080/getdata
I want to call the web service through curl which take an parameter {"time":"2016-3-30 13:47:13"}
can any one help me with syntax
curl -i -X POST -H "Content-Type: application/json" -d "{\"time\":\"2016-3-30 13:47:13\"}" http://localhost:8080/getdata
I'm trying to POST the simple data to the Parse server using REST, but not able to do so, here is the code
#include<curl/curl.h>
curl -X POST \
-H "X-Parse-Application-Id: xxxxxxxxxx" \
-H "X-Parse-REST-API-Key: xxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' \
https://api.parse.com/1/classes/GameScore
what is X here? do we need to define x? what connection settings need to be used to post the data successfully? and where is the return object is Json, where is is stored?
thanks.
You are trying to use a terminal command in C++, this won't work. X is a command line option for curl.
Below is a basic example of an HTTP POST request submitted with Curl using C. You should be able to adapt this to your needs.
http://curl.haxx.se/libcurl/c/http-post.html
Do you guys know how I can use the Curl command line to POST SOAP to test a web service?
I have a file (soap.xml) which has all the soap message attached to it I just don't seem to be able to properly post it.
Thanks!
Posting a string:
curl -d "String to post" "http://www.example.com/target"
Posting the contents of a file:
curl -d #soap.xml "http://www.example.com/target"
For a SOAP 1.2 Webservice, I normally use
curl --header "content-type: application/soap+xml" --data #filetopost.xml http://domain/path
Wrong.
That doesn't work for me.
For me this one works:
curl
-H 'SOAPACTION: "urn:samsung.com:service:MainTVAgent2:1#CheckPIN"'
-X POST
-H 'Content-type: text/xml'
-d #/tmp/pinrequest.xml
192.168.1.5:52235/MainTVServer2/control/MainTVAgent2
curl -H "Content-Type: text/xml; charset=utf-8" \
-H "SOAPAction:" \
-d #soap.txt -X POST http://someurl
If you want a fluffier interface than the terminal, http://hurl.it/ is awesome.