Try to send time to azure

I’m trying to send time and date values by json to azure, but when I send the values I get strange characters.

someone could help me or explain how I can send date and time values; I know that the date and time of publication is sent by json but I need to publish the values that I obtain in my code.


void loop(){
        delay(10);                      // even cicuits need a break
        digitalWrite(D2, HIGH);         // activate trigger
        digitalWrite(D2, LOW);          // de-activate trigger

        duration = pulseIn(D6, HIGH);   // how long until a reply?
                                        // a blocking call so may wait a few seconds
        startTime=Time.format(, "%H:%M:%S");

    if(clienteStart>0 && cliente>0){
        endTime=Time.format(, "%H:%M:%S");
        char payload[255]; 
        snprintf(payload, sizeof(payload), "{\"organization\":\"%s\",\"agencia\":\"%s\",\"ventanilla\":\"%s\",\"cliente\":%d,\"timeini\":\"%s\",\"timefin\":\"%s\"}", Org, Agen, Vent, cliente,(String) startTime,(String) endTime);  
        Particle.publish("event-data-ab01", payload);
        publishDisplay((String) cliente,startTime,endTime);
    //    Particle.publish("StartTime");
    //  publishDisplay((String) distance,(String) cliente,(String) clienteStart); 

event data:



snprintf() has no formatting scheme for String objects, so what you effectively are doing is fooling snprintf() into believing that the address of the String object is the address of the acutal string (character array), which it isn’t.
You should rather write this

        snprintf(payload, sizeof(payload), "{\"organization\":\"%s\",\"agencia\":\"%s\",\"ventanilla\":\"%s\",\"cliente\":%d,\"timeini\":\"%s\",\"timefin\":\"%s\"}", Org, Agen, Vent, cliente,(const char*)startTime,(const char*)endTime);  
        Particle.publish("event-data-ab01", payload, PRIVATE);

The String class has a dedicated cast operator overload (const char*) that actually returns the address of the internal string.

BTW, I’d avoid using String wherever possible on embedded devices and rather go with pure C char arrays.
Also if you only want to have the current time you’d only write endTime=Time.format("%H:%M:%S");


thanks @ScruffR, now send correct data on console, but i have a problem now.

Well, this is my first application sending azure information. The problem I have is that I can not store in the blob storage that I created.
I took the steps that photon recommends in the documentation to connect with azure and perform every step that indicates azure to save the messages in the Blos Storage but when I review the information it appears empty.
I apologize for this, but I can not find a solution to this problem.
thank you for your patience.

This is a configuration about particle and azure:

I’m not using Azure, since they don’t seem to offer a permanently free account for testing in Europe and I’d not have any other need for it than assisting the community.

So I’ll have to defer you to someone who has actual Azure experience - e.g. @rickkas7

1 Like

thanks @ScruffR,
Hello @rickkas7, can you help me please? I’ll be very greatful

Unfortunately I’ve never used the Azure integration either.

Thanks my friends,

i try to resolve this problem in other topic.