}If i call "volume-up" and get my test prints and then call "volume-stop" nothing happens.If i call "volume-stop" first and then again i see that "test" has a value of "1".Also "volume-up" is then printed just once.

It is cause its the payload.The topic says MQTT so this is about the Arduino pubsubclient.

Quote

But it sure doesn't have to have the meaningless name "callback".

It is not meaningless if you know MQTT in conjunction with Arduino cause it's part ofthe pubsubclient (Arduino client for MQTT).

And everything is working great. Switching house lights, TV programs, Doorbell ring through Asterisk over VoIPto Softphones, 1-Wire sensor logging to MariaDB....I only can't get this stupid loop stop to work.

I do it with voice commands.The idea was if i say "TV volume up" that the Arduino sends the IR signal until i say "volume stop".Volume up works but i can't stop it.

The server sends payload "volume-up" to the Arduino and runs it and it's working.But if i send then the payload "volume-stop" it does not stop running "volume-up".If i check my "int test" after sending "volume-stop" it's set to "1" but does not effect the running "volume-up" loop.

if (length == 9 && strncmp((char*)payload,"volume-up",9)==0) { for (int i = 0; i < 1000; i++) { Serial.println("up"); Serial.println(test); delay(50); if (test == 1) { break; } } }If the payload IS "volume-up", the for loop starts running. It does NOT end, and is not interrupted, until it completes. During that time, the value of test does not change.

while(test == 1) { Serial.println("up"); if (test == 0) { goto outer; } }outer:;in the void loop.What i'm missing or doing not how all the other examples i see are done:http://forum.arduino.cc/index.php?topic=41706.msg302984#msg302984First answer: http://stackoverflow.com/questions/863172/how-can-i-break-out-of-two-nested-for-loops-in-objective-chttp://letsmakerobots.com/node/37905

If i call "volume-up" and get my test prints and then call "volume-stop" nothing happens.

Insufficient information. What test prints do you get? What happens when you call "volume-stop". "Nothing happens" is meaningless. Does it keep printing "up"? Does it stop printing "up"? If it does stop, is it because of the timeout (ie. "up" is printed 1000 times)? Does it print "stop"?

Quote

If i call "volume-stop" first and then again i see that "test" has a value of "1".Also "volume-up" is then printed just once.

Of course. Once test has been set to 1, you will break out of the for loop after the first time though it.

Why are you testing for length in the two if statements? You are doing strncmp() with the length of the desired compare string. Granted, it's slightly faster to check for length, and not bother with the compare if it's not the right length. Are you worried about speed? If you already know the length of the payload, you don't need strncmp(), and if you don't, your "if length --" may be preventing you from getting into the second if.

There are 10 kinds of people in the world,those who understand binary, and those who don't.

// Connect to Broker, give it Optimus Prime as the name if (client.connect("Optimus Prime")) { // Publish a message to the status topic client.publish("status","Optimus Prime is now online"); // Listen for messages on the control topic client.subscribe("skulltronics.net/hive/floor/optimus-prime/#"); }

}

void loop() { client.loop();}If i don't do the "strncmp length test" then my "for loop" is not running.There is another way with a running for loop:

} // End MQTT CallbackThe second example means i have to call every command with his own topic and send "1" as message.From my point of view it makes more sense to call the remote (IR-SonyTV) and send as messagewhat to do (volume-up) instead of calling the remote, then the button and tell the button what to do.It has to do with null- termination and there is more about it here (comment 50 to 60): http://knolleary.net/arduino-client-for-mqtt/Also i have to do it like in the first example if i want to send the IR-Remote hex code over MQTT.

Ok, what this code now does is printing "running" if i send "volume-ups".I the send "volume-stop" and "running" is still printed.After the 250 "running" prints i get my:

Quote

New message from broker on topic: skulltronics.net/hive/floor/optimus-prime/IR-SonyTVPayload: volume-stopTest: 0

print.

If i send then "volume-ups" as expected "running" is only printed once and Test: 1So setting "test" works.

I need to send every command minimum 3 times to the IR-LED. That is how Sony remotes work.You press a button and the IR-LED blinks 3 times.So for my non-stop volume up i normally need:3 blinks 50ms pause 3 blinks 50ms pause...until i say "volume-stop"

void loop() { client.loop();}Will be called over and over again, right? Which means that you will be getting something every time you press a button on your remote, and from the sound of it, more than one code being received is normal operation. So this calls the MQTT broker, and that returns something.

Questions:It is important that you check for the presence of the string "skulltronics.net/hive/floor/optimus-prime/IR-SonyTV" ?If not, don't even bother with it... just check for the presence of any payload that you are interested in.If it is important, ie. if it is something you need to check to determine if there is a new payload, try something like this (assuming that the payload contents you are interested in have a maximum length of 20).

Now, remembering that client.loop() is called VERY often, you will see that callback will be called often as well.

With this code, you should keep entering the if statement for volume-up until you receive a colume-stop. At that point, you NULL terminate message[], and stop entering either if block.

Now if you want to still set a maximum number of volume-up events, you could use a static variable in callback() and limit the number by incrementing it and making the value of it part of the volume-up if conditions.

What do you think?

There are 10 kinds of people in the world,those who understand binary, and those who don't.

So after "volume-stop" the output (code that needs to be running) is empty on "volume-up".By other words i can't turn the volume up after stopping it before.Look at 6. after calling "volume-ups" a second time there is a "p" at the end of the message.Where does that come from?