I am currently retrieving data from a Campbell Scientific data logger. This data is being posted to an application that is coded in Typescript using Express and BodyParser. The request successfully reaches the app (as I'm able to debug it), however, the body/query appears as Object{}.
To ensure that the data logger is indeed sending data, I created a simple PHP program that dumps the post data along with its headers:
$json_params = file_get_contents("php://input");
$log->lwrite($json_params);
$headers = apache_request_headers();
foreach ($headers as $header => $value) {
$log->lwrite('header:'.$header.' Value:'.$value);
}
The output of this script is:
[26/Aug/2019:17:10:59] (test - 12452) {"head": {"transaction": 0,"signature": 11786,"environment": {"station_name": "idtest","table_name": "Tabla1","model": "CR300","serial_no": "1646","os_version": "CR310.Std.08.01","prog_name": "CPU:19014_Badajoz_Inundacion_Dev1.CR300"},"fields": [{"name": "Voltage","type": "xsd:float","units": "Volts","process": "Avg","settable": false},{"name": "Temp","type": "xsd:float","units": "Grados C","process": "Avg","settable": false},{"name": "HR","type": "xsd:float","units": "%HR","process": "Smp","settable": false},{"name": "Lluvia","type": "xsd:float","units": "mm","process": "Tot","settable": false},{"name": "Distancia","type": "xsd:float","units": "cm","process": "Avg","settable": false},{"name": "Calado","type": "xsd:float","units": "cm","process": "Avg","settable": false}]},"data": [
{"time": "2019-08-26T17:09:00","no": 0,"vals": [12.26,"NAN","NAN",0,"NAN","NAN"]}]}
`[26/Aug/2019:17:10:59] (test - 12452) header:User-Agent Value:CR310.Std.08.01`
`[26/Aug/2019:17:10:59] (test - 12452) header:Host Value:192.168.1.33`
[26/Aug/2019:17:10:59] (test - 12452) header:Transfer-Encoding Value:chunked
- It seems that there is a line break in the JSON after '"data": [' which may be causing the issue. Could it be related to the transfer-encoding type?
This suggests that there might be an error in my Typescript application.
this.app = express();
this.port = port;
this.app.use(bodyParser.urlencoded({ extended: true }));
this.app.use(bodyParser.json());
this.router = express.Router();
this.router.post(this.path_campbellStation
this.updateCampbellStationPost);
In the same application, I gather information from another data logger that sends data through a GET request, and it works perfectly fine with the same code. I am unsure if I need to handle this particular data logger differently (perhaps with special options in BodyParser), because when I debug the Typescript app, I can only see the headers while the body, parameters, raw, query... appear empty (Object {}).
https://i.stack.imgur.com/NRCYI.png
Thank you!