2017-01-27 4 views
0

NodeMCU를 사용하여 이벤트 허브에 이벤트를 보낼 수 있습니다. 다음 코드REST를 사용하여 Azure 이벤트 허브에 일괄 이벤트 보내기

https://www.hackster.io/stepanb/proof-of-concept-nodemcu-arduino-and-azure-event-hub-a33043

를 사용하지만 배치 이벤트를 보내려고합니다. 나는 여기에 우리가

에 "콘텐츠 형식"을 변경해야하는 링크 당으로 하나의 이벤트

single event

를 보내는 NodeMCU의 시리얼 모니터의 스냅 샷의 그

https://docs.microsoft.com/en-us/rest/api/eventhub/send-batch-events

이 페이지를 참조

Content-Type: application/vnd.microsoft.servicebus.json 

이고 페이로드는

data= "[{'Temperature':25.25 , 'Deviceid':esp3} , {'Temperature':30.30 , 'Deviceid':esp3}]"; 

여기

batch events

내가 뭔가를 놓치고 있습니까 배치 이벤트에 대한 일련 모니터의 스냅 샷입니다? 배치 이벤트를 수신하려면 스트림 분석에서 변경해야합니다. 저는 Azure와 StackOverflow를 처음 사용합니다.

여기에 하나의 이벤트

#include <ESP8266WiFi.h> 
#include <WiFiClientSecure.h> 
#include <String.h> 
#include "sha256.h" 
#include "Base64.h" 

// START: Azure Evet Hub settings 
const char* KEY = "dhGE6MbbRLe6IPZs6dOHd3byQlEJ8YzqnW+uBAT7T/Q="; // main event hub key 
const char* KEY_NAME = "RootManageSharedAccessKey";     // key name 
const char* HOST = "rishieventhub2.servicebus.windows.net";   // event hub name 
const char* END_POINT = "/rishidata/messages";      // name of eventhub created inside event hub 
// END: Azure Evet Hub settings 

// START: WiFi settings 
const char* SSID = "Nokia"; 
const char* PASSWORD = "rishikesh"; 
// END: WiFi settings 
String request; 
String data; 
String fullSas; 
WiFiClientSecure client; 
void setup() { 
    Serial.begin(115200); 
    Serial.println(); 
    Serial.println(); 

    // START: Naive URL Encode 
    String url = "https://" + (String)HOST + (String)END_POINT; 
    url.replace(":", "%3A"); 
    url.replace("/", "%2F"); 
    Serial.println(url); 
    // END: Naive URL Encode 

    // START: Create SAS 
    // https://azure.microsoft.com/en-us/documentation/articles/service-bus-sas-overview/ 
    // Where to get secods since the epoch: local service, SNTP, RTC 
    int expire = 1711104241; 
    String stringToSign = url + "\n" + expire; 

    // START: Create signature 
    Sha256.initHmac((const uint8_t*)KEY, 44); 
    Sha256.print(stringToSign); 
    char* sign = (char*) Sha256.resultHmac(); 
    int signLen = 32; 
    // END: Create signature 

    // START: Get base64 of signature 
    int encodedSignLen = base64_enc_len(signLen); 
    char encodedSign[encodedSignLen]; 
    base64_encode(encodedSign, sign, signLen); 
    String encodedSas = (String) encodedSign; 
    // Naive URL encode 
    encodedSas.replace("=", "%3D"); 
    Serial.println(encodedSas); 
    // END: Get base64 of signature 

    // SharedAccessSignature 
    fullSas = "sr=" + url + "&sig="+ encodedSas + "&se=" + expire +"&skn=" + KEY_NAME; 
    // END: create SAS 

    // START: Wifi connection 
    Serial.print("connecting to "); 
    Serial.println(SSID); 

    WiFi.begin(SSID, PASSWORD); 
    while (WiFi.status() != WL_CONNECTED) { 
    delay(1000); 
    Serial.print("."); 
    } 

    Serial.println(""); 
    Serial.println("WiFi connected"); 
    Serial.println("IP address: "); 
    Serial.println(WiFi.localIP()); 
    // END: Wifi connection 

} 
int temp=15; 
void loop() { 
    WiFiClientSecure client; 
    if (!client.connect(HOST, 443)) { 
    Serial.println("connection failed"); 
    return; 
    } 

    //data= "[{'Temperature':25.25 , 'Deviceid':'esp3'} , {'Temperature':30.30 , 'Deviceid':'esp3'}]"; // for batch events 
    data = "{'Temperature':25.25 , 'Deviceid':'esp3'}"; // for single events 
    request = String("POST ")+"https://rishieventhub2.servicebus.windows.net" + END_POINT + "?timeout=60&api-version=2014-01" + " HTTP/1.1\r\n" + 
       "Host: " + HOST + "\r\n" + 
       "Authorization: SharedAccessSignature " + fullSas + "\r\n" +     
       "Content-Type: application/atom+xml;type=entry;charset=utf-8\r\n" + 
       "Content-Length: " + data.length() + "\r\n\r\n" + 
       data; 
    Serial.println(request); 
    client.print(request); 

delay(100); 

하나의 이벤트를 보내기위한 코드 작동하고 난 테이블 저장에 값을 저장할 수 있어요 그리고 난 푸른 테이블 저장을 사용하여 볼 수 있습니다를 전송하는 코드입니다. 여기에 내가 위의 코드는 배치 이벤트를 보내기위한 작업 배치 이벤트

#include <ESP8266WiFi.h> 
#include <WiFiClientSecure.h> 
#include <String.h> 
#include "sha256.h" 
#include "Base64.h" 

// START: Azure Evet Hub settings 
const char* KEY = "dhGE6MbbRLe6IPZs6dOHd3byQlEJ8YzqnW+uBAT7T/Q="; // main event hub key 
const char* KEY_NAME = "RootManageSharedAccessKey";     // key name 
const char* HOST = "rishieventhub2.servicebus.windows.net";   // event hub name 
const char* END_POINT = "/rishidata/messages";      // name of eventhub created inside event hub 
// END: Azure Evet Hub settings 

// START: WiFi settings 
const char* SSID = "Nokia"; 
const char* PASSWORD = "rishikesh"; 
// END: WiFi settings 
String request; 
String data; 
String fullSas; 
WiFiClientSecure client; 
void setup() { 
    Serial.begin(115200); 
    Serial.println(); 
    Serial.println(); 

    // START: Naive URL Encode 
    String url = "https://" + (String)HOST + (String)END_POINT; 
    url.replace(":", "%3A"); 
    url.replace("/", "%2F"); 
    Serial.println(url); 
    // END: Naive URL Encode 

    // START: Create SAS 
    // https://azure.microsoft.com/en-us/documentation/articles/service-bus-sas-overview/ 
    // Where to get secods since the epoch: local service, SNTP, RTC 
    int expire = 1711104241; 
    String stringToSign = url + "\n" + expire; 

    // START: Create signature 
    Sha256.initHmac((const uint8_t*)KEY, 44); 
    Sha256.print(stringToSign); 
    char* sign = (char*) Sha256.resultHmac(); 
    int signLen = 32; 
    // END: Create signature 

    // START: Get base64 of signature 
    int encodedSignLen = base64_enc_len(signLen); 
    char encodedSign[encodedSignLen]; 
    base64_encode(encodedSign, sign, signLen); 
    String encodedSas = (String) encodedSign; 
    // Naive URL encode 
    encodedSas.replace("=", "%3D"); 
    Serial.println(encodedSas); 
    // END: Get base64 of signature 

    // SharedAccessSignature 
    fullSas = "sr=" + url + "&sig="+ encodedSas + "&se=" + expire +"&skn=" + KEY_NAME; 
    // END: create SAS 

    // START: Wifi connection 
    Serial.print("connecting to "); 
    Serial.println(SSID); 

    WiFi.begin(SSID, PASSWORD); 
    while (WiFi.status() != WL_CONNECTED) { 
    delay(1000); 
    Serial.print("."); 
    } 

    Serial.println(""); 
    Serial.println("WiFi connected"); 
    Serial.println("IP address: "); 
    Serial.println(WiFi.localIP()); 
    // END: Wifi connection 

} 
int temp=15; 
void loop() { 
    WiFiClientSecure client; 
    if (!client.connect(HOST, 443)) { 
    Serial.println("connection failed"); 
    return; 
    } 

    data= "[{'Temperature':25.25 , 'Deviceid':'esp3'} , {'Temperature':30.30 , 'Deviceid':'esp3'}]"; // for batch events 
    // data = "{'Temperature':25.25 , 'Deviceid':'esp3'}"; // for single events 
    request = String("POST ")+"https://rishieventhub2.servicebus.windows.net" + END_POINT + "?timeout=60&api-version=2014-01" + " HTTP/1.1\r\n" + 
       "Host: " + HOST + "\r\n" + 
       "Authorization: SharedAccessSignature " + fullSas + "\r\n" +     
       "Content-Type: application/vnd.microsoft.servicebus.json" +"\r\n" + 
       "Content-Length: " + data.length() + "\r\n\r\n" + 
       data; 
    Serial.println(request); 
    client.print(request); 

delay(100); 

} 
+0

텍스트의 스크린 샷을 복사하여 붙여 넣을 수있는 이유는 무엇입니까? 그리고 모든 관련 코드는 게시물 자체 내에 있어야하며 결국에는 죽을 링크 뒤에 있지 않아야합니다. –

답변

0

를 보내려고하고있는 코드입니다. 하나의 변화는 스트림 분석에서 출력을위한 파티션 키와 행 키에 다른 키가 필요하다는 것입니다 (테이블 스토리지). 여기서 단일 이벤트를 보내는 경우 파티션과 행 키는 동일 할 수 있습니다.