TL;DR:
I need to read the time off of my Hologram Nova USB cellular modem on /dev/ttyACM0 and update the system clock after the pi restarts. I'd like to do it in Python but it isn't reading the serial tty correctly.
My build
- I'm running python 2.7.13 on Raspbian 9
- I'm using pyserial 3.2.1-1
- I have a Pi 3 b+
- The modem is a USB connected U-Blox SARA-U201 (AKA Hologram Nova)
What works so far:
- My cellular modem is sitting on
/dev/ttyACM0 - I can communicate with it using
screen /dev/ttyacm0 9600 - I can get a time stamp in the
screensession by typingAT+CCLK?and hittingEnter
Here is the output from the screen session
AT+CCLK?
+CCLK: "19/05/16,21:31:47-16"
OK
What doesn't work so far:
- I have tried to use pyserial to interrogate the tty and return the time stamp.
- I have tried to create an
expectscript usingscreen - I'd prefer not to do this with an
expectscript when python is a lot better. - I'll post my source for
expectif this can't be done in Python.
Python Code:
import serial import time, sys import datetime response = '' SERIAL_PORT = "/dev/ttyACM0" ser = serial.Serial(SERIAL_PORT, baudrate = 9600, timeout = 5) ser.write("AT+CCLK?\r") response = ser.readline() print response When using the python console the line ser.write("AT+CCLK?\r") results in a 9 being returned on the next line. response remains empty and ser.inWaiting() is equal to 0. For further clarification hereHere is a screenshot of my attempt to query the modemtext returned from the tty:
root@raspberrypi:/home/pi# python Python 2.7.13 (default, Sep 26 2018, 18:42:22) [GCC 6.3.0 20170516] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import serial >>> import time, sys >>> import datetime >>> response = '' >>> SERIAL_PORT = "/dev/ttyACM0" >>> ser = serial.Serial(SERIAL_PORT, baudrate = 9600, timeout = 5) >>> ser.write("AT+CCLK?\r") 9 >>> response = ser.readline() >>> print response 