Insert a variable in a Python > Cellular AT command - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Insert a variable in a Python > Cellular AT command (/thread-19594.html) |
Insert a variable in a Python > Cellular AT command - ElectronicsNut - Jul-06-2019 I am an ElectronicsNut that is venturing into foreign coding territory. I have a Raspberry Pi that I have connected to a FONA 3G cellular module via port ttyUSB0. The attached code is up and running, but I would like to modify the line of code in Python script with a variable that would be used to specify a specific ALERT. The current test message that is sent to my cell phone in the code is "ALERT MESSAGE" (for testing purposes), which I would like to make a variable called "Alert Message". Based on the coding that I write, the Alert Messages could be: Fridge Low Temperature Alert Freezer Low Temperature Alert Low Water Pressure Alert No AC voltage ..... I just need to figure out how to insert the variable in that line of code (see below). I left the rcv and print lines in for testing purposes. Thanks in advance for any assistance import serial import RPi.GPIO as GPIO import os, time port = serial.Serial("/dev/ttyUSB0", baudrate=115200, timeout=1) rcv = port.read(10) print rcv port.write('AT'+'\r\n') rcv = port.read(10) print rcv port.write('ATE0'+'\r\n') rcv = port.read(10) print rcv port.write('AT+CMGF=1'+'\r\n') rcv = port.read(10) print rcv port.write('AT+CMGS="xxxxxxxxxx" '+'\r\n') rcv = port.read(10) print rcv [b]port.write('ALERT MESSAGE'+'\r\n')[/b] rcv = port.read(10) print rcv port.write("\x1A") rcv = port.read(10) print rcv port.close() RE: Insert a variable in a Python > Cellular AT command - joe_momma - Jul-07-2019 hello your question isn't clear to me. Does your code output all the write messages to your phone? How are you checking temperature or water pressure? In this example POWER is set to True: if POWER == False: format_text= 'Alert Message %s'%('No A/C') port.write(format_text+'\r\n') rcv = port.read(10) print rcv |