Problem sorted, though I don't know why.
I took out the hyphens in the Pot-Left & Right strings, and made them Pleft and 
Pright. and it does not crash.

Peter.

On 23/08/2021 18:29, PeterMerchant wrote:
I have three versions of this program, and two work, but the third with the 
differences put together crashes.   Can anybody advise me what is happening.

Here are the relevant bits.

1. Working


def on_message(client, userdata, message):
   if message.payload  == b'forward':
      up_15()
   elif message.payload  == b'slow':
      down_15()
   elif message.payload  == b'stop':
      on()
   elif message.payload  == b'motorleft':
      motorleft()
   elif message.payload  == b'motorright':
      motorright()
   elif message.payload  == b'backwards':
      mbackwards()
   else:
      print(message.payload)

the stuff in quotes 'forward' etc is the message payload that I act on.

2 Working

def on_message(client, userdata, message):
   if message.payload  == b'forward':
      up_15()
   elif message.payload  == b'slow':
      down_15()
   elif message.payload  == b'stop':
      on()
   elif message.payload  == b'Pot-left':
      motorleft()
   elif message.payload  == b'Pot-rt':
      motorright()
   elif message.payload  == b'backwards':
      mbackwards()
   else:
      print(message.payload)

the left and right have been changed to Potentiometer values

and 3, not working


def on_message(client, userdata, message):
   if message.payload  == b'forward':
      up_15()
   elif message.payload  == b'slow':
      down_15()
   elif message.payload  == b'stop':
      on()
   elif message.payload  == b'motorleft':
      motorleft()
   elif message.payload  == b'motorright':
      motorright()
   elif message.payload  == b'Pot-left':
      motorleft()
   elif message.payload  == b'Pot-rt':
      motorright()
   elif message.payload  == b'backwards':
      mbackwards()
   else:
      print(message.payload)

Actually the Pot-rt lines have been commented out. It did work with both the 
Pot-* bits commented out.


Thanks for any thoughts.




--
 Next meeting: Online, Jitsi, Tuesday, 2021-09-07 20:00
 Check to whom you are replying
 Meetings, mailing list, IRC, ...  http://dorset.lug.org.uk
 New thread, don't hijack:  mailto:dorset@mailman.lug.org.uk

Reply via email to