Here is the Python 2.7.16 code I quickly put together to send unix time to the Arduino UNO.
I assume it also works on Python3, but I have not tested it because I have not completely upgrade python on my mac pro yet, sorry about that.
Code:
# -----------------------------------------------------------
# Sync Unix Time with Arduino Initial Draft 0.1
# Written on macOS, tested with Python 2.7.16
# Neo, December 2019
# This code needs refinement to be more general
# I will improve this code later when I need to use it in an Arduino project
# For now, it works "OK" and serves it purpose
# Feel free to improve, modify as you like.
# -----------------------------------------------------------
import serial
import time
ser = serial.Serial(
port='/dev/cu.usbserial-40', #change this for your device
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=0)
print("connected to: " + ser.portstr)
# this will store the line
line = []
ux = 0
a = False
debugScript = False
offset = 2 . #adjust this time offset (in seconds) to account for various time delays in script and transferring via the serial port, etc. to insure the Arduino is in closer sync to the computer
time_int = 1000 # this can be any number greater than zero and less than recent unix time
count = 0
while True:
if debugScript:
print(str(int(time.time())))
for c in ser.read():
if not a:
if ux < time_int:
ser.write("T")
ux = int(time.time())+offset
ser.write(str(ux))
ser.write("\n")
ser.flush()
if debugScript:
print("unixtime: " + str(ux))
line.append(c)
count += 1
if c == '\n':
print("Line("+str(count)+"): " + ''.join(line))
x = int(time.time())+offset
print("time("+str(count)+"): " + str(x) + "\n")
line = []
a = True
break
ser.close()
I am assigned a programming work.It is my first time to use unix.
The task is writing a shell script to interrogate the university Unix operating system to determine the number of "Runnable" processes at any given time.Then append the result,along with a time-stamp,on a log file. Also there are... (1 Reply)
I have a list of interfaces and time the interface was last active. I can't figure out how to convert the time in the second column,
Fa1/14 0
Se0/0/0 0
Fa1/11 0
Fa1/9 0
Fa1/0 0
Se0/0/1 1240401408
Gi1/0 0
Fa0/0 1240401408
Fa1/3 0
Fa1/8 0
Fa1/15 0
Fa1/13 0
Fa1/10 0
Fa1/1 0
Fa1/12... (7 Replies)
Here is two time I have:
Jul 12 16:02:01
Jul 13 01:02:01
and how can I do a simple match to get difference between two time which is 09:00:00
Thanks in advance. (3 Replies)
I'd like to convert a date string in the form of sun aug 19 09:03:10 EDT 2012, to unixtime timestamp using awk.
I tried
This is how each line of the file looks like, different date and time in this format
Sun Aug 19 08:33:45 EDT 2012, user1(108.6.217.236) all: test on the 17th
... (2 Replies)
I needed some help in adding a duration (in seconds) to a start time (in hhmmss format) and a start date (in mmddyy format) in order to get an end date and end time. The concept of a leap year is also to be considered while incrementing the day. The code/ function that I have formed so far is as... (3 Replies)
Hi guys thanks for the help for my previous posts.Now i have a requirement that i download a XMl file which has UTC time stamp.I need to convert UTC time into Unix server timezone.
For ex if the time zone of unix server is CDT then i need to convert into CDT.whatever may be the system time... (5 Replies)
In my further exploration of Arduino, today I decided to install the arduino-cli on my mac today.
https://github.com/arduino/arduino-cli
I followed the instructions for macOS but when I got to this part:
arduino-cli board list
I got the dreaded "Unknown" Fully Qualified Board Name... (1 Reply)
Discussion started by: Neo
1 Replies
LEARN ABOUT DEBIAN
cyclades-ser-cli
cyclades-ser-cli(8)cyclades-ser-cli(8)NAME
cyclades-ser-cli Serial Port Interface for Cyclades Terminal Servers
SYNOPSIS
cyclades-ser-cli [options] devname rasname physport
DESCRIPTION
The cyclades-ser-cli program connects a Unix device file 'devname' to a physical port 'physport' of a Cyclades Terminal Server 'rasname'.
cyclades-ser-cli provides the I/O interface between the device file and the physical port, running as an 'user-mode device driver'.
If 'physport' is assigned to 0, then 'rasname' is used as the IP address on an IP-based serial port addressing.
OPTIONS
cyclades-ser-cli may be started with the following options:
-u ptyiosize
Sets the internal device I/O size to ptyiosize (maximum 4096 bytes, default 1024 bytes)
-n netiosize
Sets the internal socket I/O size to netiosize (maximum 512 bytes, default 128 bytes)
-i retrydelay
Delay in seconds between connection requests (default: 60)
-r retries
Number of connection request retries before exiting. (default: infinity)
-s Use the Socket Server protocol for talking to the server, this means just piping all the data down a TCP connection with no control
information, so it's impossible to change the port speed etc. The default is to use the RFC2217 protocol.
-m modem handling
The default is 0 which means to check DCD state, 1 means to ignore DCD.
-c close mode
Last close handling; the default is 0 which means to hangup the modem, 1 means not to hangup.
-p start port
TCP base port of servers at terminal server side (defaults: 31000 for Socket server, 30000 for Remote Telnet Server). Note: if
'physport' is assigned to zero, this option has no effect, the Telnet Server standard port (23) is used.
-d debug level
The default is debug level 0 (little debugging), level 1 debugs internal state changes, level 2 debugs events, and level 3 debugs IO
calls.
-f Run in foreground, this is suitable for running from init.
-x Console mode: normally all messages are sent to syslogd (using local2 facility). With this option, all messages will be sent to std-
out and cyclades-ser-cli runs in the foreground. This implies -f
USE
Every instance of cyclades-ser-cli will have a virtual serial device which is a sym-link to a pseudo-tty. A terminal program can then talk
to the virtual serial device and it's data transfers will be redirected across the network. Each virtual serial device will be accompanied
by a Unix domain socket with the same name with the addition of ".control". So if cyclades-ser-cli provides the virtual device named
"/dev/modem" then it will have a control socket named "/dev/modem.control". There is a shared object named libcyclades-ser-cli.so which
intercepts calls to the tcsetattr() and tcsendbreak(). This shared object then sends the relevant data to the cyclades-ser-cli server via
the control socket. To recognise a virtual modem device it has to read /etc/cyclades-devices.
The libcyclades-ser-cli.so shared object can be loaded per-application through the LD_PRELOAD environment variable, or for the entire sys-
tem through the system shared object configuration (see the OS documentation). Note that the LD_PRELOAD environment variable has to have
the fully qualified path of the object, otherwise an application which changes it's current directory may fail.
BUGS
In Solaris libcyclades-ser-cli.so does not work with the stty program. stty uses a different interface to this and requires some extra
coding.
In Solaris libcyclades-ser-cli.so conflicts with some system programs such as ps for unknown reasons. Just don't load it for those pro-
grams, it has no such problems with any serial comms programs.
EXAMPLES
Start an interface between /dev/prt1 device and a serial port number 10 of a Terminal Server named pr01, without hangup at last close:
cyclades-ser-cli -c 1 /dev/prt1 pr01 10
In general use do not start cyclades-ser-cli from the command line, start it through the cyclades-serial-client script or from init.
SEE ALSO cyclades-serial-client(1), cyclades-devices(5)cyclades-ser-cli(8)