Closed supekshala closed 3 years ago
try it with ArduinoHttpClient library over WiFiEspAT as you use ESP8266HTTPClient library over ESP8266WiFi.
your code building the HTTP request has many errors. there is no path in request line, Host and Content-Length values are wrong and the empty line separating the headers and the content is missing.
Could you please correct this post request code. That would be a huge help. Iam really frustrated because of this. what should put to server and URI. Only I got from power bi dataset is this API URL=> https://api.powerbi.com/beta/d1323671-cdbe-4417-b4d4-bdb24b51316b/datasets/60dfb0df-9bf8-4c05-8505-69a32ec90a95/rows?tenant=&UPN=&key=H1wfQ3c5rxxmgrDqcZkARXK%2FCypXYyN77IDXoYA13z5%2FnXN9JRAXGehl15Tb0is43ikRShQauxuQH45p%2FJV8dg%3D%3D
Should I separate this URL like this? Server="api.powerbi.com" URI="beta/d1323671-cdbe-4417-b4d4-bdb24b51316b/datasets/60dfb0df-9bf8-4c05-8505-69a32ec90a95/rows?tenant=&UPN=&key=H1wfQ3c5rxxmgrDqcZkARXK%2FCypXYyN77IDXoYA13z5%2FnXN9JRAXGehl15Tb0is43ikRShQauxuQH45p%2FJV8dg%3D%3D"
if (client.connect(server, 443)) {
Serial.println(F("con..."));
// send the HTTP GET request:
String content = "{\"temperature\":\""+String(value)+"\"}";
client.println("POST " + URI + " HTTP/1.1");
client.println("Host: " + String(server));
client.println("Content-Type: application/json");
client.print("Content-Length: ");
client.println(content.length());
client.println();
client.println(content);
// note the time that the connection was made:
} else {
// if you couldn't make a connection:
Serial.println(F("con failed"));
}
use ArduinoHttpClient
I tried several times to connect and a post request to power bi but I don't how to do it using AT commands. I attempt to do it below code. but I doesnt work.
/*
Simple POST client for ArduinoHttpClient library
Connects to server once every five seconds, sends a POST request
and a request body
created 14 Feb 2016
modified 22 Jan 2019
by Tom Igoe
this example is in the public domain
*/
#include <WiFiEspAT.h>
#include <ArduinoHttpClient.h>
/////// Wifi Settings ///////
char ssid[] = "SLT_FIBRE";
char pass[] = "kavindusupekshala";
char serverAddress[] = "https://api.powerbi.com/beta/d1323671-cdbe-4417-b4d4-bdb24b51316b/datasets/60dfb0df-9bf8-4c05-8505-69a32ec90a95/rows?key=H1wfQ3c5rxxmgrDqcZkARXK%2FCypXYyN77IDXoYA13z5%2FnXN9JRAXGehl15Tb0is43ikRShQauxuQH45p%2FJV8dg%3D%3D"; // server address
int port = 443;
WiFiClient wifi;
HttpClient client = HttpClient(wifi, serverAddress, port);
int status = WL_IDLE_STATUS;
void setup() {
Serial.begin(115200);
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to Network named: ");
Serial.println(ssid); // print the network name (SSID);
// Connect to WPA/WPA2 network:
Serial3.begin(115200);
WiFi.init(Serial3);
WiFi.begin(ssid, pass);
status = WiFi.begin(ssid, pass);
}
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
}
void loop() {
int value=10;
String postData ="[{\"temperature\":\" "+String(value)+"\"}]";
Serial.println("making POST request");
String contentType = "application/json";
client.post("/", contentType, postData);
// read the status code and body of the response
int statusCode = client.responseStatusCode();
String response = client.responseBody();
Serial.print("Status code: ");
Serial.println(statusCode);
Serial.print("Response: ");
Serial.println(response);
Serial.println("Wait five seconds");
delay(5000);
}
With AT 1.7 WiFiEspAT doesn't support secure connection (WiFiSSLClient for https). Even with AT 2.1 TLS 1.2 is not supported by AT firmware and it is very possible that powerbi uses TLS 1.2 for https.
servername is only "api.powerbi.com"
post("/"
should be post("/beta/d1323671-cdbe....
Thanks. Do you know a firmware that can support TLS 1.2?if so I can install that firmware to the board
I need to send data to the power bi dashboard using arduinomega+esp8266 inbuilt board. I successfully install AT firmware and test example codes. but still, I could not manage to make the post request to power bi streaming data set API. Previously I used a nodemcu board to this task and it worked flawlessly. this is the code I used in nodemcu.
This the code I tried in Arduino mega +ESP8266 board but it didn't work.
This is the dataset I tried to connect. API = https://api.powerbi.com/beta/d1323671-cdbe-4417-b4d4-bdb24b51316b/datasets/60dfb0df-9bf8-4c05-8505-69a32ec90a95/rows?tenant=&UPN=&key=H1wfQ3c5rxxmgrDqcZkARXK%2FCypXYyN77IDXoYA13z5%2FnXN9JRAXGehl15Tb0is43ikRShQauxuQH45p%2FJV8dg%3D%3D
[ { "temperature" :98.6 } ]