Giter Site home page Giter Site logo

Comments (6)

OllisGit avatar OllisGit commented on June 12, 2024 3

@HumamHelfawi : Thx for the hint!

I changed AWS_IOT.cpp as follows, so that the correct topicname is passed to the custom-function:

void iot_subscribe_callback_handler(AWS_IoT_Client *pClient, char *topicName, uint16_t topicNameLen,
        IoT_Publish_Message_Params *params,
		void *pData)
{
	char shortTopic[512];
	strncpy(shortTopic, topicName, topicNameLen);

	if (subApplCallBackHandler != 0) //User call back if configured
		subApplCallBackHandler(shortTopic, params->payloadLen,
				(char *) params->payload);
}

from hornbill-examples.

muneebmalik78 avatar muneebmalik78 commented on June 12, 2024 2

@OllisGit Thank you for your answer but the shortTopic Contains some Junk Characters at the end which can be avoided by adding following line after strncpy(shortTopic, topicName, topicNameLen);
shortTopic[topicNameLen] = 0;

from hornbill-examples.

gadget-man avatar gadget-man commented on June 12, 2024

I have the same error - I need to check the topicName as I'm subscribing to multiple topics. Did you find a solution?

from hornbill-examples.

gadget-man avatar gadget-man commented on June 12, 2024

Found a solution - in your callbackhander, add the following:

int topicNameLen = strlen(topicName);
topicName[(topicNameLen - payloadLen)] = 0;

EDIT: Correction - this doesn't work, because the length of the topicName doesn't get truncated, so it remains the size of the first submission.

from hornbill-examples.

HumamHelfawi avatar HumamHelfawi commented on June 12, 2024

The original handler

void iot_subscribe_callback_handler(AWS_IoT_Client *pClient, char *topicName, uint16_t topicNameLen,
has topicNameLen parameter which is very important. However, the custom handler does not have this one.
You should edit the the library and add this field for custome handler.

One other note, the library supports only one subscription. If you make another subscription, it will override the old one.

from hornbill-examples.

intelligentandgoodlooking avatar intelligentandgoodlooking commented on June 12, 2024

@OllisGit Good spotting! I have also implemented your fix
@muneebmalik78 good work on the null terminator. Always have to be careful of strncpy... it will not null terminate if it hits the n'th character.
You have to do it manually, or use:
snprintf(shortTopic, topicNameLen + 1,"%s", topicName);

from hornbill-examples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.