Skip to main content
Modified the code to allow for breaks in the loop if time cannot be read. Repeat the loop every 20 seconds til successful.
Source Link
Shrout1
  • 172
  • 1
  • 11

Ok turns out I am an impatient man.

I need to modify this code so thatwas simply requesting the data too quickly; screen stays connected and shows it doesn't loop eternally, but this works forPython is just too fast when it reads the moment (willinput.

This code attempts to read the time from the modem at 2/10 of a second intervals for 20 seconds. If unsuccessful it sleeps for 20 seconds and then tries again. It will return the datetime string that is provided to this):the modem. That can be parsed from the "response" variable.

import serial import time, sys import datetime response = '' SERIAL_PORT = "i=0 time_found=False response='' SERIAL_PORT="/dev/ttyACM0" ser = serialser=serial.Serial(SERIAL_PORT, baudrate = 9600, timeout = 15)   while time_found==False: ser.write('AT+CCLK?\r')  response = ser.readline()  while "CCLK:" not in response: response = ser response=ser.readline() time.sleep(0.2) ++i if i==200: break if "CCLK:" in response: time_found=True else: time.sleep(20)   print response 

I was simply requesting the data too quickly; screen stays connected and shows it, Python is just too fast when it reads the input.

I will put some kind of a sleep value in the loop and then timeout the loop if it fails to read. I may put the overall script in a loop with a 10 minute delay so that it will run until successful.

Ok turns out I am an impatient man.

I need to modify this code so that it doesn't loop eternally, but this works for the moment (will return to this):

import serial import time, sys import datetime response = '' SERIAL_PORT = "/dev/ttyACM0" ser = serial.Serial(SERIAL_PORT, baudrate = 9600, timeout = 15) ser.write('AT+CCLK?\r') response = ser.readline() while "CCLK:" not in response: response = ser.readline() print response 

I was simply requesting the data too quickly; screen stays connected and shows it, Python is just too fast when it reads the input.

I will put some kind of a sleep value in the loop and then timeout the loop if it fails to read. I may put the overall script in a loop with a 10 minute delay so that it will run until successful.

Ok turns out I am an impatient man.

I was simply requesting the data too quickly; screen stays connected and shows it, Python is just too fast when it reads the input.

This code attempts to read the time from the modem at 2/10 of a second intervals for 20 seconds. If unsuccessful it sleeps for 20 seconds and then tries again. It will return the datetime string that is provided to the modem. That can be parsed from the "response" variable.

import serial import time, sys import datetime i=0 time_found=False response='' SERIAL_PORT="/dev/ttyACM0" ser=serial.Serial(SERIAL_PORT, baudrate = 9600, timeout = 15)   while time_found==False: ser.write('AT+CCLK?\r')  response = ser.readline()  while "CCLK:" not in response:  response=ser.readline() time.sleep(0.2) ++i if i==200: break if "CCLK:" in response: time_found=True else: time.sleep(20)   print response 
edited body
Source Link
Shrout1
  • 172
  • 1
  • 11

Ok turns out I am inan impatient man.

I need to modify this code so that it doesn't loop eternally, but this works for the moment (will return to this):

import serial import time, sys import datetime response = '' SERIAL_PORT = "/dev/ttyACM0" ser = serial.Serial(SERIAL_PORT, baudrate = 9600, timeout = 15) ser.write('AT+CCLK?\r') response = ser.readline() while "CCLK:" not in response: response = ser.readline() print response 

I was simply requesting the data too quickly; screen stays connected and shows it, Python is just too fast when it reads the input.

I will put some kind of a sleep value in the loop and then timeout the loop if it fails to read. I may put the overall script in a loop with a 10 minute delay so that it will run until successful.

Ok turns out I am in impatient man.

I need to modify this code so that it doesn't loop eternally, but this works for the moment (will return to this):

import serial import time, sys import datetime response = '' SERIAL_PORT = "/dev/ttyACM0" ser = serial.Serial(SERIAL_PORT, baudrate = 9600, timeout = 15) ser.write('AT+CCLK?\r') response = ser.readline() while "CCLK:" not in response: response = ser.readline() print response 

I was simply requesting the data too quickly; screen stays connected and shows it, Python is just too fast when it reads the input.

I will put some kind of a sleep value in the loop and then timeout the loop if it fails to read. I may put the overall script in a loop with a 10 minute delay so that it will run until successful.

Ok turns out I am an impatient man.

I need to modify this code so that it doesn't loop eternally, but this works for the moment (will return to this):

import serial import time, sys import datetime response = '' SERIAL_PORT = "/dev/ttyACM0" ser = serial.Serial(SERIAL_PORT, baudrate = 9600, timeout = 15) ser.write('AT+CCLK?\r') response = ser.readline() while "CCLK:" not in response: response = ser.readline() print response 

I was simply requesting the data too quickly; screen stays connected and shows it, Python is just too fast when it reads the input.

I will put some kind of a sleep value in the loop and then timeout the loop if it fails to read. I may put the overall script in a loop with a 10 minute delay so that it will run until successful.

Source Link
Shrout1
  • 172
  • 1
  • 11

Ok turns out I am in impatient man.

I need to modify this code so that it doesn't loop eternally, but this works for the moment (will return to this):

import serial import time, sys import datetime response = '' SERIAL_PORT = "/dev/ttyACM0" ser = serial.Serial(SERIAL_PORT, baudrate = 9600, timeout = 15) ser.write('AT+CCLK?\r') response = ser.readline() while "CCLK:" not in response: response = ser.readline() print response 

I was simply requesting the data too quickly; screen stays connected and shows it, Python is just too fast when it reads the input.

I will put some kind of a sleep value in the loop and then timeout the loop if it fails to read. I may put the overall script in a loop with a 10 minute delay so that it will run until successful.