2017-05-24 13 views
1

내 ESP8266에 프로그래밍하고 하나의 주제를 구독하여 청취 메시지를 유지합니다. 이것은 IBM Iot 노드에 메시지를 주입하는 그래픽보기입니다.메시지가 IBM Bluemix의 ESP8266에 게시되지 않습니다.

enter image description here

이것은 분사보기

enter image description here

이 IBM 여잔 노드의 내 설정이다의 내 설정이다. 여기

enter image description here

시리얼 모니터에 내 로그, 그것은 연결 채널 cmd를에 가입되어

enter image description here

지금까지 너무 좋아, 내 IBM에 메시지를 삽입하려고 할 때 노드가 없다면 메시지를 게시하지 않습니다. 직렬 모니터에 도달하지 않고 디버그 뷰에 로그온하지 않기 때문입니다. 여기 당신이 볼 수 있습니다 여기에

enter image description here

소스 코드입니다 : 내가 cf 명령을 사용하여 클라우드 파운드리 로그를 확인하려고

#include <ESP8266WiFi.h> 
#include <PubSubClient.h> // https://github.com/knolleary/pubsubclient/releases/tag/v2.3 

const char* ssid = "shiv"; 
const char* password = "[email protected]"; 

#define ORG "2kafk4" 
#define DEVICE_TYPE "ESP8266" 
#define DEVICE_ID "5CCF7FEED6F0" 
#define TOKEN "[email protected]*mGkb_" 

char server[] = ORG ".messaging.internetofthings.ibmcloud.com"; 
char topic[] = "iot-2/cmd/test/fmt/String"; 
char authMethod[] = "use-token-auth"; 
char token[] = TOKEN; 
char clientId[] = "d:" ORG ":" DEVICE_TYPE ":" DEVICE_ID; 

WiFiClient wifiClient; 

void callback(char* topic, byte* payload, unsigned int payloadLength) { 
    Serial.print("callback invoked for topic: "); Serial.println(topic); 

    for (int i = 0; i < payloadLength; i++) { 
    Serial.print((char)payload[i]); 
    } 
} 
PubSubClient client(server, 1883, callback, wifiClient); 

void setup() { 
    Serial.begin(115200); 
    Serial.println(); 
    wifiConnect(); 
    mqttConnect(); 
} 

void loop() { 
    if (!client.loop()) { 
    mqttConnect(); 
    } 
} 

void wifiConnect() { 
    Serial.print("Connecting to "); Serial.print(ssid); 
    WiFi.begin(ssid, password); 
    while (WiFi.status() != WL_CONNECTED) { 
    delay(500); 
    Serial.print("."); 
    } 
    Serial.print("nWiFi connected, IP address: "); Serial.println(WiFi.localIP()); 
} 

void mqttConnect() { 
    if (!client.connected()) { 
    Serial.print("Reconnecting MQTT client to "); Serial.println(server); 
    while (!client.connect(clientId, authMethod, token)) { 
     Serial.print("."); 
     delay(500); 
    } 
    initManagedDevice(); 
    Serial.println(); 
    } 
} 

void initManagedDevice() { 
    if (client.subscribe(topic)) { 
    Serial.println("subscribe to cmd OK"); 
    } else { 
    Serial.println("subscribe to cmd FAILED"); 
    } 
} 

, 여기있다 https://pastebin.com/dfMaS1Gd

은 누구도 날 내가 무엇을 암시 할 수 잘못하고있는거야? 미리 감사드립니다.

+0

@valerielampkin 의견 있으십니까? –

+0

IoTin 노드에는 무엇이 있습니까? 나는 기본적으로 문자열이 아닌 json을 기대한다고 생각합니다. – ValerieLampkin

+0

나는 하나의 튜토리얼을 보았고, 그들은 문자열의 예를 들었다. 어쨌든 JSON은 { "name": "williams"}처럼 https://i.stack.imgur.com/hFbIa.png에 삽입하고 IOT 노드의 형식을 json으로 변경합니다. 나는 당신이 의미하는 바를 원한다. –

답변

1

노드 유형에서 장치 유형이 올바르게 지정되었는지 확인하십시오. 현재 스크린 샷은 등록한 기기 유형 및 코드에 지정된 기기 유형과 일치하지 않는 0.16.2를 표시합니다.

+0

@ nop77svk 어떻게? 이것은 나에게 대답을 보인다! –

+0

네 말이 맞아. 미안하지만, 내 실수 야. – nop77svk