使用arduino从网站上阅读文本

时间:2016-07-07 05:39:41

标签: arduino

我想连接到api并将令牌密钥参数发送到此服务器并从该页面返回文本。

例如,我想连接到此页面:

154.12.32.5:153?token=V6bFm8tVc8vFJMNQWUPY8Ag3dLzR6SKE

我使用Ethernet shild和Arduino uno。

你能帮助我吗?

1 个答案:

答案 0 :(得分:0)

使用示例代码可以更好地解释这一点:

byte mac[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };  // See sticker on your shield
byte ip[] = { 10, 0, 0, 177 };
byte server[] = { 154, 12, 32, 153 };  // IP from your question

EthernetClient client;

void setup()
{
    Ethernet.begin(mac, ip);
    delay(1000);  // wait a second so things are settled up ...

    if (client.connect(server, 153)) {  // Port from your question
        client.println("GET /?token=V6bFm8tVc8vFJMNQWUPY8Ag3dLzR6SKE HTTP/1.0");
        client.println();
    } else {
        // Connection failed code ...
    }
}

void loop()
{
    if (client.available()) {
        char c = client.read();
        // Do something with data ...
    }
}