Hi,
I'm a new member of CSI Forum
I have CR310 datalogger, I want to send data to web using HTTPost instruction
This is my code send data to web:
RealTime (Time())
ts = Time(1)
WriteString = "ts,rain,water,temp,salt,drain,volt " + CHR(13)+ ts +","+ PositionGate + ","+ IntDataStation1(1) +","+ IntDataStation1(2) + ","+ RealDataStation1(1) +","+ RealDataStation1(2) + ","+ RealDataStation1(3)
OpenFile1 = FileOpen ("CPU:CR300data1.csv","w",-1)
FileWrite (OpenFile1,WriteString,0)
CloseStat=FileClose (OpenFile1)
http_header = "X-ApiKey: text/csv" 'enter unique ApiKey here
http_post_tx = HTTPPost ("https://api.qt.vntoken.org/api/a/add", "CPU:Batt_Volt.csv", http_post_response, http_header)
And CR310 return header results:
HTTP/1.1 500 Internal server error
Content type: Aplication/JSON
Acces-control-allow
In CR300, I using Device Configuration Utility config IP same IP Address class with rounter
When I test by API Online tool "https://reqbin.com", it is ok
Link check result: https://api.qt.vntoken.org/api/a/list
Can Pro show me fix the error?
1) X-ApiKey doesn't do what you think it does:
https://swagger.io/docs/specification/authentication/api-keys/
2) is your goal to transmitt more than one timestamp worth of data? If not, why go through the trouble of sending a csv file if instead you can just transmit the string directly as per the HTTPPost() example in CRbasic?
3) if you got control over the server you might want to check his logs to see what he receives from the logger to find what goes wrong? And maybe try something simpler first like HTTPGet and a HTTP request instead of HTTPS?
If your ReqBin test works with your server and your CRbasic code doesn't then the server logs should tell you what goes wrong..
Or in other words - we don't know how the server side api looks like that you are working against and I doubt anyone will be able to help you without it nor will you get help for this here (try web-oriented forums like stack overflow for the particular server api/programming language you are using).
Thanks for your support, Nico
I fixed the error,
1. File format error:
WriteString = "ts,rain,water,temp,salt,drain,volt " + CHR(10)+ CHR(13)+ ts +","+ PositionGate + ","+ IntDataStation1(1) +","+ IntDataStation1(2) + ","+ RealDataStation1(1) +","+ RealDataStation1(2) + ","+ RealDataStation1(3)
2. Change Header
http_header = "Content-Type: text/plain"
Dear all,
I have CR300-Cell 200
I send data to web using HTTPost instruction via LAN port is ok.
So now, I want to send data to web using HTTPost instruction via Cellular Network.
I installed 3G/4G data sim for CR300-Cell 200
Can you show me how to configure CR300-Cell 200 for Cellular Network communication?
Thanks a lot!