Python Forum
Insert a variable in a Python > Cellular AT command
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Insert a variable in a Python > Cellular AT command
#1
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()
Reply


Messages In This Thread
Insert a variable in a Python > Cellular AT command - by ElectronicsNut - Jul-06-2019, 02:10 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Insert 10gb csv files into sql table via python mg24 2 1,949 Apr-28-2023, 04:14 PM
Last Post: snippsat
  Python Serial: How to read the complete line to insert to MySQL? sylar 1 835 Mar-21-2023, 10:06 PM
Last Post: deanhystad
  python insert blank line in logger mg24 1 2,864 Nov-02-2022, 08:36 AM
Last Post: snippsat
  store all variable values into list and insert to sql_summary table mg24 3 1,168 Sep-28-2022, 09:13 AM
Last Post: Larz60+
  How to write a part of powershell command as a variable? ilknurg 2 1,132 Jul-26-2022, 11:31 AM
Last Post: ilknurg
  Insert a multiple constant value after header in csv file using python shantanu97 1 1,160 Apr-24-2022, 10:04 AM
Last Post: Pedroski55
  Os command output in variable shows wrong value paulo79 2 1,523 Apr-09-2022, 03:48 PM
Last Post: ndc85430
  How to use a variable in linux command in python code? ilknurg 2 1,614 Mar-14-2022, 07:21 AM
Last Post: ndc85430
  Command output to Variable ironclaw 1 1,792 Aug-26-2021, 06:55 PM
Last Post: bowlofred
  insert row and write to xlsx in python scttfnch 0 2,025 Feb-28-2021, 01:19 AM
Last Post: scttfnch

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020