I’m sending some events back and forth between two Cores. Publishing and subscribing to events work and the subscribe handler function is called but the const char* event pointer seems to not point at the event name.
To test this I wrote a handler function for the Spark.subscribe() like this:
void eventHandler(const char* event, const char* data){
Spark.publish(event, data);
//Other stuff, witch is executed without problem
}
It publishes the event name and the data back to the cloud and then does other stuff not important to this problem.
This function runs on one of the cores. The other sends an event witch triggers this function an the result is this:
I was expecting to get the exact same event name and data back, but clearly this is not the case. I have also tried to compare the event name in code and lighting a LED if the match to make sure this is not an error from the publish() method.
Does anyone know what the issue might be? Is there something wrong with my code or is something broken?
Sure! It’s quite long, but you will find the important parts I’m sure.
The application is for monitoring that a machine is still running and then calling for assistance. Base monitors the machine and the node is like a pager sort of.
So i realized that my previous entry contained lot of code not relevant to the problem and therefore i made a minimalistic example with the same error. The setup is sort of the same: one Core (Base) will publish an event named “AnEventName” and the other core (Node) will subscribe to that event and publish the event name and data again.
I find this problem extremly strange. Scince the Spark.publish() is called with the const char* event and const char* data in exactly the same way and the data part gets published correctly I can’t think of why this should not work.
Any ideas, or might this be a firmware bug? Since the handler function is indeed called the event name must have gotten to the Core properly, but mabye the part of the firmware that calls this function fails to supply the correct pointer as an argument?
Casting to a string solved the problem! I still find it strange that the data argument got passed correctly and not the event argument, but I can live with that fact.
The code you provided indeed caused an infinate loop due to recursion but that was expected I guess.
The recursion is not really an issue. I’m later going to compare the event and data fields with locally saved strings and just wanted to make sure that it gets trough correctly, so I won’t be republishing like that in the finished version.