extract json with nodered - json

I want to extract json part in a message with node red
I receive the message in node red but I can't extract the data
exemple of a message:
POST / HTTP/1.1
Host: xxx.xx.xxx.5:9000
User-Agent: libcurl-agent/1.0
Content-type: application/json
Accept: application/json
Content-Length: 526
{
"timestamp": 1571997083,
"data": {
"temperature": 20.613545532227,
"humidity": 61.3828125,
"battery": 3.47
},
"frame": "814962xxxx16a1dc5",
"gatewayID": "AA555Axxxx0xx964",
"othersGW": [],
"clientID": "xxxx",
"DevAddr": "011xxxxb",
"DevEUI": "8cf9xxx000000xxx",
"sensorInstallId": "8cf95xxx0000xxxx",
"loraPort": 8,
"fcnt": 1607,
"rxpk": {
"tmst": 2380181019,
"time": "2019-10-25T09:51:23.472998Z",
"chan": 0,
"rfch": 0,
"freq": 867.1,
"stat": 1,
"modu": "LORA",
"datr": "SF7BW125",
"codr": "4/5",
"lsnr": 9,
"rssi": -72,
"size": 22,
"data": "xxxxxxxxxxxxxxxx/YxWg=="
}
}
so I would like to have data of temperature etc...
and I don't know the node I have to use
Thanks a lot

Having got a better view of what you are trying to do from the comments.
Using the TCP-in node is probably not the right approach for this. You will do much better using the HTTP-in/HTTP-out nodes as these will handle dealing with all the HTTP-header and sending a proper response to the client so the connection gets closed.
The HTTP-in node takes a path e.g. /input which will be appended to the Node-RED URL giving something like http://localhost:1880/input. It also takes a HTTP verb which in this case would be POST. You can find more details and lots of examples in the Node-RED cookbook here.
You will need to update the client to point to the correct path and port.

You will need JSON node to convert the message string into an object.
Nodered has a very good documentation and hands on examples.
See below for some help:
This is great example how to to use the json node
This
describes how to work with JSON data

Related

Is there any documentation for EasyPost that shows the raw JSON for the requests, including headers? Or e.g. a PostMan collection?

I'm just doing the preparation for an integration with EasyPost's Shipping API, which will be server side C#, but we always build a PostMan collection for new integrations, so that we can test data separately from the application if there's an issue.
While I do love the fact that EP provide C# libraries and examples, I'm struggling to find anything that just gives me a list of required headers and the raw JSON format for the body of any requests. It feels a bit like they're just being a little too helpful.
I'll be looking at the Orders endpoint probably.
I've got an account, I've checked all their documentation and searched the internet but haven't found anything so I'm hoping I'm not the first developer to want to use a client application for testing outside my code.
Update:
EasyPost now does have a public workspace https://www.postman.com/easypost-api
with at least 1 public collection
The curl examples are basically the same as json:
For the Address creation example:
-d "address[street1]=417 MONTGOMERY ST"
is the equivalent of
{ "address": { "street1": "417 MONTGOMERY ST" } }
(you might have to escape some characters to be valid json).
Check out How to stimulate cURL request to a request using postman for postman with HTTP Basic Auth.
EasyPost does not provide a public Postman collection; however, here is an example of a shipment Postman body (raw) that could be used. You can adjust the values, actions, objects, etc to your needs.
Using the following, you shouldn't need to pass any headers. You'll pass your API key under the username field with the Basic Auth authorization type.
{
"shipment": {
"to_address": {
"id": "adr_123..."
},
"from_address": {
"id": "adr_123..."
},
"parcel": {
"id": "prcl_123..."
},
"carrier_accounts": {
"id": "ca_123..."
},
"options": {
"address_validation_level": "0"
}
},
"format": "json",
"controller": "shipments",
"action": "create"
}

HTTP 406 not acceptable response header fiddler

I am using fiddler 4 as a frond-end service for elasticsearch.
I'm trying to store a document into index using API following this.
Here's my sample json as request body:
{
"fruit": "Apple",
"size": "Large",
"color": "Red"
}
API : http://localhost:9200/food/fruit
method :POST HTTP/1.1
Here's the response:
As mentioned in their doc., "Starting from Elasticsearch 6.0, all REST requests that include a body must also provide the correct content-type for that body." adding content-type: application/json in the request solved the issue.

FineUploader Failing to parse incoming JSON

I'm using play/scala for a webapp and a scala API, currently running simply on two different ports on localhost:9000 and localhost:8080 respectively. I have the basic page from the fine-uploader.com website docs, and a simple test page build in Play. (FWIW, i don't think much of the above is relevant)
When i post a file, chunked or not, Fine uploader receives a 200 from the API and valid JSON, but JSON.parse returns a failure. The logging from fine-uploader is below. If i take this output and run it through (in the console)
JSON.parse(JSON.stringify(json))
a valid object is returned. I can't just JSON.parse(json) directly in the browser tools b/c its already an object. I have checked the types by console.log'ing typeOf json in the qq.parseJson method and it returns string, so no conversion should be required, though i have tried it with the same results.
fine-uploader console logs:
[Fine Uploader 5.5.1] Sending simple upload request for 0 fine-uploader.js:251
[Fine Uploader 5.5.1] xhr - server response received for 0 fine-uploader.js:251
[Fine Uploader 5.5.1] responseText = {"code":"UPLOAD_COMPLETE","response":{"MediaModel":{"id":1103,"publicUri":"http://localhost:8080/media/Archive.zip","fileLocation":"/src/services/api/src/main/webapp/media/Archive.zip","mediaDate":{"year":2016,"month":2,"day":28},"mediaOrder":1,"viewName":"","caption":"","altText":"","isPublic":1,"fileSize":1107080,"created":"2016-02-28T14:58:43Z"},"UserMediaModel":{"id":1,"userId":24,"mediaId":3,"created":"2016-02-17T12:48:18Z"}},"errors":[]} fine-uploader.js:251
[Fine Uploader 5.5.1] Received response status 200 with body: {"code":"UPLOAD_COMPLETE","response":{"MediaModel":{"id":1103,"publicUri":"http://localhost:8080/media/Archive.zip","fileLocation":"/src/services/api/src/main/webapp/media/Archive.zip","mediaDate":{"year":2016,"month":2,"day":28},"mediaOrder":1,"viewName":"","caption":"","altText":"","isPublic":1,"fileSize":1107080,"created":"2016-02-28T14:58:43Z"},"UserMediaModel":{"id":1,"userId":24,"mediaId":3,"created":"2016-02-17T12:48:18Z"}},"errors":[]} fine-uploader.js:251
[Fine Uploader 5.5.1] Simple upload request failed for 0
The server is responding with a 200 per the API logs and i can see the exact response object in the Response tab of Chrome Dev tools.
I added a custom error handler, but not more more information was provided, just that the error is the text output
Error on file number 0 - Archive.zip. Reason: {"code":"UPLOAD_COMPLETE",....same as above
Lastly, all rows are propery inserted into the database as you see from the id's created above. And all logging points to an equally successful action.
Thanks for any pointers. I've also put this output in http://jsonlint.com/ and it parses fine.
Thanks! (sorry for the lack of JSON formatting, i can change it, but this seemed long enough already)
EDIT
It seems that i have satisfied the requirements stated in the other question with "success":true and Content-Type=text/plain. The following, per request is the JSON output and the headers
Headers:
Key: Access-Control-Allow-Origin Value: http://localhost:9000
Key: Date Value: Mon, 29 Feb 2016 00:55:19 GMT
Key: Access-Control-Allow-Credentials Value: true
Key: Content-Type Value: text/plain; charset=UTF-8
{
"code": "UPLOAD_COMPLETE",
"response": {
"MediaModel": {
"id": 1169,
"publicUri": "http://localhost:8080/media/Archive.zip",
"fileLocation": "/src/services/api/src/main/webapp/media/Archive.zip",
"mediaDate": {
"year": 2016,
"month": 2,
"day": 28
},
"mediaOrder": 1,
"viewName": "",
"caption": "",
"altText": "",
"isPublic": 1,
"fileSize": 1107080,
"created": "2016-02-29T00:55:19Z"
},
"UserMediaModel": {
"id": 1,
"userId": 24,
"mediaId": 3,
"created": "2016-02-17T12:48:18Z"
}
},
"errors": [],
"success": true
}
I'm sure this will end up being something silly, so i appreciate the input.
Based on the error reported by Fine Uploader, your response is not properly formatted. If you look closely at the response in your browser's network tab (such as with Chrome dev tools), you'll likely see a JSON string that, once parsed using JSON.parse results in another JSON string instead of a JavaScript object containing the expected properties. I can't confirm this as you haven't posted the exact response from your server, but I'm certain that this is the case. This is most likely caused by an encoding issue server-side. For example, your server should return this: {"foo": "bar", "success": true} instead of this: "{\"foo\": \"bar\", \"success\": true}". I suspect your server is returning the latter.

Orion Context Broker - Query By Location

Following with queries in Orion v0.24.
As pointed out in previous related questions, documentation is ahead to real implementation. Is filter by location with 'geometry' and 'coord' already implemented?
Can anyone provide a query example. I do not understand what/how to pass coordinates. From docs:
List of coordinates (separated by ;) are interpreted depending on the geometry
I tried the following unsuccesfully:
//Call 1
http://<some-ip>:<some-ip>/v2/entities/?type=Test&geometry=polygon&coords=35.46064,-9.93164;35.46066,3.07617;44.33956,3.07617;44.33955,-9.93164
//Result
{
"error": "BadRequest",
"description": "invalid character in URI parameter"
}
I tried similar combinations, filtering special characters with encodeURIComponent, but nothing.
Entities in orion have following attribute 'coordenadas':
{
"id": "Test.1",
"type": "Test",
"coordenadas": {
"type": "geo:point",
"value": "43.7723705, -7.6784461"
},
"fecha": 1440108000000,
"regiones": [
"ES"
]
}
EDIT 03/11/2015
We have updated Orion to version 0.25 where geometry queries are expected to be implemented using NGSI v2.
A call to
http://<some-ip>:<some-ip>/version
reports us the update has been done correctly:
<orion>
<version>0.25.0</version>
<uptime>0 d, 2 h, 23 m, 17 s</uptime>
<git_hash>a8cf800d4e9fdd7b4293a886490c40309a5bb58c</git_hash>
<compile_time>Mon Nov 2 09:13:05 CET 2015</compile_time>
<compiled_by>fermin</compiled_by>
<compiled_in>centollo</compiled_in>
</orion>
Nonetheless, the queries seem to not work properly. Following with the examples used above, a geometrical query like this should return an entity:
http://<some-ip>:<some-ip>/v2/entities?type=Test&geometry=circle;radius:6000&coords=43.7723705,-7.6784461
Unfortunately, the response is an empty array.
We have also tried a geometrical query using a polygon:
http://<some-ip>:<some-ip>/v2/entities?type=Test&geometry=polygon&coords=40.199854,-4.045715;40.643135,-4.045715;40.643135,-3.350830;40.199854,-3.350830
Again, the response is the empty array.
It seems like the location property of the entity, "coordenadas", is not being detected. So I tried creating a new entity to see if the problem is all entities were created before the update to v0.25, but it did not work.
EDIT 04/11/2015
The request we are building for entity creation is the following:
POST /v2/entities/ HTTP/1.1
Accept: application/json, application/*+json
Content-Type: application/json;charset=UTF-8
User-Agent: Java/1.7.0_71
Host: 127.0.0.1:1026
Connection: keep-alive
Content-Length: 379
{
"id":"Test.1",
"type":"Test",
"nombreEspecie":"especietest",
"coordenadas":{
"type":"geo:point",
"value":"3.21456, 41.2136"
},
"fecha":1446624226632,
"gradoSeguridad":1,
"palabrasClave":"test, test, test",
"comentarios":"comentarios, comentarios",
"nombreImagen":"ImagenTest",
"alertas":[],
"regiones":[],
"validacionesPositivas":0,
"validacionesNegativas":0,
"validacionesDenunciadas":0
}
As you suggested we tested the entity creation in a new and clean instance of Orion. The creation was done correctly, but location query is still not working...
The examples are correct, but that functionality is not available yet in Orion 0.24.0 or any previous version. It has been already implemented in the develop branch (see corresponding issue at github.com repository, now closed). It will be available in the version next to 0.24.0, either 0.24.1 or 0.25.0 (number not yet decided at the moment of writting this) by the end of september 2015.
EDIT: Orion 0.25.0 implements geometry and coord URL parameters, but the location definition is still based in NGSIv1 mechanism. Thus, instead of using geo:point use a metadata named location to mark that the associated attribute is the location:
"coordenadas": {
"location": {
"type": "string",
"value": "WGS84"
},
"type": "geo:point",
"value": "3.21456, 41.2136"
}
This "asymmetry" (i.e. NGSIv1 to define location but NGSIv2 geo-query support) will desappear as we progress in NGSIv2 implementation (take into accoun that in Orion 0.25.0, NGSIv2 is still in beta status).

Deserialization error when trying to use JSON with HBASE's REST gateway

I'm trying to use the hbase rest API. I've read the docs here (http://wiki.apache.org/hadoop/Hbase/Stargate), but they seem to be incomplete (doesn't cover json) and out of date.
I've also run across this gist, which is mostly what I'm going off of.
Here is the (insert) request I'm trying to send:
URI: http://server:8070/table/row1/data
Headers:
Content-Type : application/json
Accept : application/json
HTTP verb - POST
and the json payload (where key, column, and $ are all base64 encoded values):
{
"Row": {
"key": "NjQ=",
"Cell": [{
"column": "NjQ=",
"$": "NjQ="
}]
}
}
Here is the error I get:
Error 500 Can not deserialize instance of java.util.List out of START_OBJECT token
at [Source: org.mortbay.jetty.HttpParser$Input#3da0b822; line: 2, column: 5]
(through reference chain: org.apache.hadoop.hbase.rest.model.CellSetModel["Row"])
The error seems to suggest that there is something that should be an array and isn't. I've tried putting square brackets just about everywhere, and I can't get it to do anything other than change the nature of the error message slightly.
I had a look through the source code and that seems to suggest that the placement for the square brackets that I have is correct. However, as far as I can tell the entire request looks to be correct. I'm not very fluent in Java though, so maybe I'm missing something.
What is the proper JSON syntax for inserting a record with the hbase rest gateway?
This is now the correct format:
{
"Row": [{
"key": "NjQ=",
"Cell": [{
"column": "NjQ=",
"$": "NjQ="
}]
}]
}
Where:
key - is the row key
column - is the column name
$ - is the data that you are storing in the given table, column, and row.