Particle Sending to Azure

Hello,

I followed one of your tutorials to integrate Particle with Microsoft Azure. I created my event hubs and made sure they work. I wrote a C# code in Visual Studio to send messages to my event hubs, and I was able to receive them.

However, it didn’t work when I tried to do it with Particle Photon. I had this JSON file from the “Hands-on-Lab Particle Photon Weather Station in Azure” on hackster.io:

{
 "event": "ctdmohweb",
 "url": "https://ctdmoh-ns.servicebus.windows.net/ehdevices",
 "requestType": "POST",
 "json": {
 "subject": "{{s}}",
 "unitofmeasure": "{{u}}",
 "measurename": "{{m}}",
 "value": "{{v}}",
 "organization": "{{o}}",
 "displayname": "{{d}}",
 "location": "{{l}}",
 "timecreated": "{{SPARK_PUBLISHED_AT}}",
 "guid":  "{{SPARK_CORE_ID}}" 
 },
 "azure_sas_token": {
 "key_name": "WebSite",
 "key": "GL8Yqti9r1wcQUm5FYfzclAnD7M/LfNxcOUcMIqHYUU="
 },
 "mydevices": true
}

and this was the firmware I flashed on the Particle board:

char payload[4];

void setup() {
    Serial.begin(9600);
    
    payload[0] = 2;
    payload[1] = 4;
    payload[2] = 6;
    payload[3] = 1;
}

void loop() {
    Spark.publish("ctdmohweb", payload);
    delay(10000);
}

It is sending test data.

The problem is I got this error on the Particle dashboard when I created the webhook:
400The requested HTTP operation is not supported in an EventHub. TrackingId:0baeeda1-cc95-4274-9b21-ede2061281f8_G46,TimeStamp:7/30/2015 9:31:06 PM

I double checked the authentication part and it was correct, and my event hub is functional too. I guess the error is with the HTTP POST operation, and the JSON file in general,

Please advise me on this, and I will appreciate any help.

Thanks,

Ping @dave

Hi @mohammedmidhat,

Your webhook is expecting that you’ll be publishing a JSON string with keys like “l”, “d”, “o”, “v”, etc, anything that has a {{something}} in your hook. So your publish statement instead should be something like:

#include "HTU21D/HTU21D.h"
 
HTU21D htu = HTU21D();
 
char Org[] = "Your org";
char Disp[] = "your display location";
char Locn[] = "your location";
 
void setup()
{
              while(! htu.begin()){
                  delay(1000);
              }
 
              delay(10000);
}
 
void loop()
{
    delay(5000);
 
              float c = htu.readTemperature();
              float f = c * (9.0/5.0) + 32;
             
    float h = htu.readHumidity();
  
    char payload[255];
   
    snprintf(payload, sizeof(payload), "{ \"s\":\"wthr\", \"u\":\"F\",\"l\":\"%s\",\"m\":\"Temperature\",\"o\":\"%s\",\"v\": %f,\"d\":\"%s\" }", Locn, Org, f, Disp);
    Spark.publish("your_event", payload);
   
    delay(5000);
   
    snprintf(payload, sizeof(payload), "{ \"s\":\"wthr\", \"u\":\"%%\",\"l\":\"%s\",\"m\":\"Humidity\",\"o\":\"%s\",\"v\": %f,\"d\":\"%s\" }", Locn, Org, h, Disp);
    Spark.publish("your_event", payload);
   
}

Thanks,
David

Thank you Dave. I tried this but I still got the same Error:
Error400The requested HTTP operation is not supported in an EventHub. TrackingId:0baeeda1-cc95-4274-9b21-ede2061281f8_G46,TimeStamp:7/30/2015 9:31:06 PM

Hi @mohammedmidhat,

Hmm, it looks like your webhook was working fine (not getting HTTP errors from event hub) over the weekend, but then stopped working. Did you use up your Azure credits by chance, or change some permissions?

Thanks,
David

Hi @Dave

So I checked my event hub history and it seems I didn’t receive any “incoming messages” on my event hub over the weekend. I only followed the tutorial I mentioned earlier to set Azure stuff, so I believe I didn’t touch any of the credits or permissions stuff.

Thanks,
Mohammed

Hi @Dave

Any advice?

Hi @mohammedmidhat,

I’m not sure, sounds like maybe something isn’t configured right on the EventHub side, maybe @dwcares might have some insights?

Thanks,
David

Thank you Dave, I already figured out the problem. It was with the url https://ctdmoh-ns.servicebus.windows.net/ehdevices
, which have /messages at the end as well.

Thanks,
Mohammed

Ah awesome, glad it’s working :smile:

Thanks,
David

Am I right in thinking this posts to the EventHub, not an IoTHub?

Guess so :wink: