Using tplinkcloud API from ESP32

This thread has been locked for further replies. You can start a new thread to share your ideas or ask questions.

Using tplinkcloud API from ESP32

This thread has been locked for further replies. You can start a new thread to share your ideas or ask questions.
Using tplinkcloud API from ESP32
Using tplinkcloud API from ESP32
2019-07-23 00:44:12
Model: HS100  
Hardware Version:
Firmware Version:

Hi Folks,

 

So I've got my first device up and running which is great, but I would like to control it from an ESP32 I'm using locally. So I've been trying to access the TP Link Cloud API and I'm not having much luck.

 

I've found snippets of code around on Github that claim to do this, but its a bit foggy and I dont feel like there is a lot of good clear official documentation.

 

I can access it from the Kasa application, and I can even access the API using curl, but from the ESP32 I always seem to get a http 400.

 

The login step to get the token looks like this:

    const char *tplinkCertificate = "-----BEGIN CERTIFICATE-----\n" \
                        "MIIDjjCCAnagAwIBAgIQAzrx5qcRqaC7KGSxHQn65TANBgkqhkiG9w0BAQsFADBh\n" \
                        "MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" \
                        "d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBH\n" \
                        "MjAeFw0xMzA4MDExMjAwMDBaFw0zODAxMTUxMjAwMDBaMGExCzAJBgNVBAYTAlVT\n" \
                        "MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j\n" \
                        "b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IEcyMIIBIjANBgkqhkiG\n" \
                        "9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuzfNNNx7a8myaJCtSnX/RrohCgiN9RlUyfuI\n" \
                        "2/Ou8jqJkTx65qsGGmvPrC3oXgkkRLpimn7Wo6h+4FR1IAWsULecYxpsMNzaHxmx\n" \
                        "1x7e/dfgy5SDN67sH0NO3Xss0r0upS/kqbitOtSZpLYl6ZtrAGCSYP9PIUkY92eQ\n" \
                        "q2EGnI/yuum06ZIya7XzV+hdG82MHauVBJVJ8zUtluNJbd134/tJS7SsVQepj5Wz\n" \
                        "tCO7TG1F8PapspUwtP1MVYwnSlcUfIKdzXOS0xZKBgyMUNGPHgm+F6HmIcr9g+UQ\n" \
                        "vIOlCsRnKPZzFBQ9RnbDhxSJITRNrw9FDKZJobq7nMWxM4MphQIDAQABo0IwQDAP\n" \
                        "BgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBhjAdBgNVHQ4EFgQUTiJUIBiV\n" \
                        "5uNu5g/6+rkS7QYXjzkwDQYJKoZIhvcNAQELBQADggEBAGBnKJRvDkhj6zHd6mcY\n" \
                        "1Yl9PMWLSn/pvtsrF9+wX3N3KjITOYFnQoQj8kVnNeyIv/iPsGEMNKSuIEyExtv4\n" \
                        "NeF22d+mQrvHRAiGfzZ0JFrabA0UWTW98kndth/Jsw1HKj2ZL7tcu7XUIOGZX1NG\n" \
                        "Fdtom/DzMNU+MeKNhJ7jitralj41E6Vf8PlwUHBHQRFXGU7Aj64GxJUTFy8bJZ91\n" \
                        "8rGOmaFvE7FBcf6IKshPECBV1/MUReXgRPTqh5Uykw7+U0b6LJ3/iyK5S9kJRaTe\n" \
                        "pLiaWN0bfVKfjllDiIGknibVb63dDcY3fe0Dkhvld1927jyNxF1WW6LZZm6zNTfl\n" \
                        "MrY=\n" \
                        "-----END CERTIFICATE-----\n";

    const char* api_url = "https://wap.tplinkcloud.com";
    const char* uuid = "myUUID";
    const char* cloudUserName = "myUsername";
    const char* cloudPassword = "myPassword";

    char body[2048];
    sprintf(body,"{ \"method\":\"login\",\"params\":{\"appType\":\"Kasa_Android\",\"cloudUserName\":\"%s\",\"cloudPassword\":\"%s\",\"terminalUUID\":\"%s\"}}", cloudUserName, cloudPassword, uuid);


    HTTPClient http;
//    http.begin("https://postman-echo.com/post", postmanCertificate);
    http.begin("https://wap.tplinkcloud.com", tplinkCertificate);
    http.addHeader("Content-Type", "application/json");
    http.setUserAgent("Dalvik/2.1.0 (Linux; U; Android 6.0.1; A0001 Build/M4B30X)");

    // tlsVersion: "TLSv1.1" ?

    int result = http.POST(body);
    Serial.print("Response Code: ");
    Serial.println(result);

    String payload = http.getString();
    Serial.print("Payload: ");
    Serial.println(payload);

    http.end();

 

As you can see, I tried testing with postman-echo and it seems to work, echoing back the paylod. One site suggested the TLS version could be the reason its been rejected but before I dig into the bowels of the C libraries that do this, is there anything else obvious I'm missing ?

 

Is there any better documentation ?

 

Does anyone have suggestions for debugging this ?

  1      
  1      
#1
Options
1 Reply
Re:Using tplinkcloud API from ESP32
2019-07-24 05:48:19

@Exie 

 

Hello, the API info is not available for end-users. 

 

Wish your kindly understanding. 

 

Nice to Meet You in Our TP-Link Community. Check Out the Latest Posts: Connect TP-Link Archer BE550 to Germany's DS-Lite (Dual Stack Lite) Internet via WAN Archer GE550 - BE9300 Tri-Band Wi-Fi 7 Gaming Router EasyMesh Is Available When Wi-Fi Routers Work in AP Mode as A Controller. Archer AX90 New Firmware Added Support for EasyMesh and Ethernet Backhaul If you found a post or response helpful, please click Helpful (arrow pointing upward icon). If you are the author of a topic, remember to mark a helpful reply as the "Recommended Solution" (star icon) so that others can benefit from it.
  0  
  0  
#2
Options

Information

Helpful: 1

Views: 4070

Replies: 1

Related Articles