I have a function call as follow:
send_at('AT+CMQPUB=0,"sensor",1,0,0,34',"hex_numbers_here",'OK',10)
I want the "34" and the "hex_numbers_here" to be variables instead of literal inputs, but my attempts to "escape" out of the quotes are failing miserably...
Please help!
I tried:
send_at('AT+CMQPUB=0,"sensor",1,0,0,'+myval+',"'+my_hex+'",'OK',10)
where myval and my_hex are the variables I created earlier in my code.
update:
I tried the following as well now:
mqtt_msg = b'testing mqtt message from sim7020'
output = binascii.b2a_hex(mqtt_msg)
length = len(output)
print(output)
output_text = str(output)
print(output_text)
f1 = 'AT+CMQPUB=0,"sensor",1,0,0,'+str(length)+',"'+output_text+'"'
f2 = 'OK'
f3 = '10'
print(f1)
AT+CMQPUB=0,"sensor",1,0,0,66,"b'74657374696e67206d717474206d6573736167652066726f6d2073696d37303230'"
The only thing noiw is that the output_text variable should not contain the b'' - making me think that the casting to str() of the hex/bit value is now doing what I think it should be doing...
BTW - I HAVE to cast the text to binary/hex - this is what the modem wants...
UPDATE:
OK, I found a way around this that is working now:
mqtt_msg = b'testing mqtt message from sim7020 - and again!'
output = binascii.b2a_hex(mqtt_msg)
length = len(output)
print(output)
output_text = str(output)
print(output_text)
output_text = output_text[2:length+2]
new_len = len(output_text)
f1 = 'AT+CMQPUB=0,"sensor",1,0,0,'+str(new_len)+',"'+output_text+'"'
f2 = 'OK'
f3 = '10'
print(f1)
I'm basically just stripping out the first 2 and last chars from the string.