首页 > 解决方案 > Arduino 无法通过 wi-fi 连接到 IBM Watson IoT。我错过了什么?

问题描述

我一直在这上面花了一些时间,但没有运气,它应该是简单的......

我想连接到 Watson 平台并从 MKR1000 Arduino 发送一个事件(一些文本)。

因为它没有连接到云,所以我在第一个障碍中跌倒了。

他们在网上的信息非常好,让我看了一两天!

如果我能得到第二双眼睛,那就太好了。

wifi 连接本身没问题,因为我在不同的代码上运行它以确认它没问题。另外,我收到一个“?” 到串行监视器,因此假设它是云连接而不是 wifi。

void connect() {
    Serial.print("checking wifi...");
    while (WiFi.status() != WL_CONNECTED) {
        Serial.print("!");
        delay(1000);
    }

    Serial.print("\nconnecting...");
    while (!client.connect("d:slqo8v:Arduino:Sender01","use-token-auth","<as 
    on the hub>")) {
        Serial.print("?");
        delay(1000);
    }

    Serial.println("\nconnected!");
}

我已将云上的安全设置减少为可选的 TLS。我已经三次检查了登录详细信息。

大部分代码如下,我不愿意把它全部贴出来,因为它说不要粘贴整个代码,但我认为我的经验还不够,这不是像放错括号那样微不足道的事情。

我展示的例子就像

client.connect("clientID", "username", "password")
IBM Bluemix 
clientID = "d:<slqo8v>:<Arduino>:<Sender01>"
username is aways: "use-token-auth"
password is: Token auth provided by Bluemix
Example:
client.connect("d:iqwckl:arduino:oxigenarbpm","use-token-auth","90wT2?a*1WAMVJStb1")    

我已经转载了这个..

    Serial.print("\nconnecting...");
    while (!client.connect("d:slqo8v:Arduino:Sender01","use-token- 
    auth","as provided online")) {
        Serial.print("?");
        delay(1000);
    }
    Serial.println("\nconnected!");
}

void setup() {
    Serial.begin(9800);
    WiFi.begin("", "");

    client.begin("slqo8v.messaging.internetofthings.ibmcloud.com", 1883, net);

    connect();
}


void loop() {
    client.loop();

    if (!client.connected()) {
        connect();
    }
}

我也切换了代码,但没有想出任何可行的方法。

非常感谢任何帮助。

谢谢!

标签: arduinomqttiotibm-watsonwatson-iot

解决方案


查看服务器端,我可以看到最新的错误是由于客户端 ID 中的空格导致未授权错误。正在使用的 clientid 是d: slqo8v:Arduino:Sender01注意 slqo8v 之前的空格。

我在您的代码示例中看不到那个空间,所以它可能是复制和粘贴中的特殊字符?或者自从这篇文章以来代码已经改变了?


推荐阅读