Can I setup Modem Manager to automatically switch back to preferred access technology? - ubuntu-18.04

I am using Modem Manager on Ubuntu 18.04 with various Sierra wireless modems, for this example it was the EM7565.
I have 4G set as my preferred access technology, and when this fails I notice the switch to UMTS (as expected).
Modes | supported: allowed: 3g; preferred: none
| allowed: 4g; preferred: none
| allowed: 3g, 4g; preferred: 3g
| allowed: 3g, 4g; preferred: 4g
| current: allowed: 3g, 4g; preferred: 4g
Is there a way to automatically switch back to 4G from UMTS when a strong enough 4G signal returns?
Presently I reset the modem and it connects back to 4G, but I want this process to be automatic.

Related

Can u-boot support more than one ethernet port?

I want to ping out of multiple ethernet ports. Is there an inherent restriction where u-boot only supports a single ethernet port?
Can u-boot support more than one ethernet port?
Yes, in recent versions of U-Boot (going back to at least 2012.10).
Salient code is eth_current_changed() and eth_set_current() in net/eth.c.
Is there an inherent restriction where u-boot only supports a single ethernet port?
No, recent versions of U-Boot can support more than one Ethernet port on the board.
When more than one Ethernet interface is available (as reported by the "Net" device list on startup, e.g. "Net: macb0, gmac0, usb_ether"), the environment variable ethact is used to define the selected Ethernet interface that is active.
Use the printenv ethact command to view the current selection.
Use the setenv ethact <port name> to change the active Ethernet port.
The U-Boot network commands, such as ping and tftpboot, will use the Ethernet port defined by the ethact variable. This preserves the command syntax with older versions of U-Boot, and the syntax is consistent regardless of the number of available ports (e.g. scripts do not change).
Each Ethernet port is assigned its own MAC address, using the following environment variables:
ethaddr: Ethernet MAC address for first/only ethernet interface (= eth0 in Linux).
This variable can be set only once (usually during manufacturing of the board). U-Boot refuses to delete or overwrite this variable once it has been set.
eth1addr: Ethernet MAC address for second ethernet interface (= eth1 in Linux).
eth2addr: Ethernet MAC address for third ethernet interface (= eth2 in Linux).
Obviously you can only (easily) access one port at a time.
There is also only one static IP address assignment, i.e. the ipaddr environment variable.
(I don't know what happens with an IP address acquired by DHCP using one port, and then the active port is changed.)
U-Boot> printenv ethact
ethact=macb0
U-Boot> setenv ethact gmac0
U-Boot> ping 192.168.1.1
gmac0: PHY present at 7
gmac0: Starting autonegotiation...
gmac0: Autonegotiation complete
gmac0: link up, 1000Mbps full-duplex (lpa: 0x2800)
Using gmac0 device
host 192.168.1.1 is alive
U-Boot>
Note that there also a rotation scheme that automatically changes the active port when the ports are down:
U-Boot> printenv ethact
ethact=gmac0
U-Boot> ping 192.168.1.1
gmac0: PHY present at 7
gmac0: Starting autonegotiation...
gmac0: Autonegotiation timed out (status=0x7949)
gmac0: link down (status: 0x7949)
ERROR: Need valid 'usbnet_devaddr' to be set
at drivers/usb/gadget/ether.c:2362/usb_eth_init()
macb0: PHY present at 0
macb0:0 is connected to macb0. Reconnecting to macb0
macb0: Starting autonegotiation...
macb0: Autonegotiation timed out (status=0x7849)
macb0: link up, 100Mbps full-duplex (lpa: 0x41e1)
Using macb0 device
ping failed; host 192.168.1.1 is not alive
U-Boot> printenv ethact
ethact=macb0
U-Boot>

How to connect to localhost from another computer

I make database program and use localhost as host. I want my friend to test my program but I don't know how to connect from another computer.
PS. I use windows 7 and MySql.
localhost is just an alias for the loopback address 127.0.0.1, which means this computer.
If you want to communicate with that computer from somewhere else, you'll need to use its real IP address.
For example, see the following "diagram" showing where connectons will go depending on the IP address used:
+-----------+ 10.1.1.8 +-----------+
| MyPC | <------- | YourPC |
| | | |
| 10.1.1.8 | -------> | 10.1.1.9 |
+-----------+ 10.1.1.9 +-----------+
| ^ | ^
| | | |
127.0.0.1-+ 127.0.0.1-+
With Windows, you should be able to get your IP address with ipconfig (ifconfig under most UNIX-type systems) and just plug that into your connection parameters where you currently have localhost.
Keep in mind that you may still need to grant power to the remote IP address to connect, such as with (assuming you're trying to connect from 10.1.1.8):
GRANT ALL PRIVILEGES ON *.* TO 'mysql'#'10.1.1.8' IDENTIFIED BY 'super-sekrit'
Are both the computers on same network? Then just provide your LAN ip address to your friend. However if you are on internet and not behind a NAT firewall then you can provide him your public ip addres. If you are behind a NAT router then you have to setup port forwarding on your router
you mean connect to your program or your DB? you can replace your "localhost" with IP address to make your program accessible from another computer.
Localhost is the standard hostname given to the address of the loopback network interface.
for communication between two computers :
Use your systems IP address.
first make sure that your system can be pinged from your friends PC.
make sure the corresponding port that your application listens on is open.

Detecting a RS-232 com port in Linux

I have an ECR(Electronic Cash Register) device,it has a RS-232 com port cable for the connection to PC but I have not been given any drivers for it. I am trying to connect the device to PC but PC is not able to detect the cable. How to detect this device attached on this RS-232? I am working under Linux. Any help on how to find the device is appreciated?
Following is the code snippet I found in C to connect to device based on Baudrate and Com Port number.
int OpenComport(int comport_number, int baudrate)
int SendByte(int comport_number, unsigned char byte)
int SendBuf(int comport_number, unsigned char *buf, int size)
Please see my answer to a related question which shows how to open and configure the serial port.
On Linux, serial ports are almost always /dev/ttyS[0123] (that is /dev/ttyS0, /dev/ttyS1, etc.) for the hardwired ports, and /dev/ttyUSB* for USB ports. The hardwired "devices" may appear only when the hardware is present on some distributions. On others, they always appear whether there is hardware or not. (Try cat /dev/ttyS2 and see if you get the error "no such device".) This is a kernel configuration option which is frequently set to create the device entries whether the hardware is there or not.
The USB ports are present only when there is hardware plugged in, but if there are multiple USB serial ports, it can be difficult identifying which is which.
There is a mechanism within /etc/udev/rules.d/* which can be configured if some aspects of the devices are consistent. See man 7 udev for details.
For applications I have written, I determine which device is which by writing to the device and identifying its response. For devices which don't respond, this is either a worthy programming challenge or a mundane configuration solution.
I think you need to do a little reading about RS-232, and well, C programming also. There are no drivers for RS-232. It is a very "dumb" protocol - you basically just shove data out the port.
The PC cannot detect the cable? That's because it's not USB. Believe it or not, Plug-and-play didn't always exist; you tell the software what port the device is supposedly connected to, and it tries to talk to it.
Furthermore, those aren't "code snippets", those are just function prototypes. There isn't any actual code there.
1>since there's no operating system on your ECR so I guess u don't need any drivers ,instead a firmware will be there in the ECR , which tries to communicate with your Linux UART driver
2> Rs-232 is basically a serial protocol , I mean it has 9 wires , and hence a connecter with 9 pins are used DB-9 connectors ,all the communications inside a processor is in parallel format so a chip called UART is used to convert all the parallel data into serial data , and since yu want to pass the data in Rs-232 format , it needs to be packaged in that format .
3> Linux kernel already has a uart driver , which is implemented for RS-232 . so need to worry about drivers from Linux side.
4> Open a terminal type " dmesg | grep tty " ( connect only the ECR to the PC for rs-232 ports ). it will return something like ttyS or ttyUSB etc , however u just concentrate on ttyS if u have connected only through rs-232 cable .
5> Once u are sure of the ttyS device from the dmesg use minicom (its easy to use ) to communicate with the device.
regards,
Zubraj

Check what serial port i'm using in linux

I have a plugged usb-serial device plugged to my windows and serial mapped it using virtualbox e.g COM1 -> /dev/ttyS0..
Now how will i know which serial port my device is using.. I know right now im using /dev/ttyS0. but what if i don't know?.. Linux Debian is creating this permanent serial port devices on boot time /dev/ttyS0-S3.
How can i make a test that /dev/ttyS0 is the real port im using in c.
Here's my way of testing if it's the right port or not.
devfd=open("/dev/ttyS0",O_WRONLY | O_NOCTTY | O_NDELAY);
if(s_fd<0) exit(1);
printf("open\n"); //It will always return true printing open because this device is created on boot time and is always available. so i made another check and that is to write to the port(Assuming i have set the permission to have full access to the serial port). if i can write to the port then it means it is really the port im using.
test=write(devfd,"ATZ",4);
if(test<0) printf("Can't write to port: Maybe not the serial port ur using\n");
printf("Device is avaialable\n"); // returns true because we can write to the port
Can you show me other samples in c of how can Check serial port if there's a device plugged to that serial port?
Or a test in c to the following serial port /dev/ttyS0 - /dev/ttyS3 if the following have devices plugged on them.
Thanks.
The Standard Serial ports are mapped as /ttyS0,/ttyS1,... as you correctly stated.
Generic USB Serial Ports as well as most G3 modems are accessible as /dev/ttyUSB0 through /dev/ttyUSB255
The better way to distinguish if a serial port 'connected' with a modem is to send ATIx commands to the serial port. These are Identity commands that you may use to detect the model name of the device and many other details.
First you try to send ATIx command not changing the baud rate. If you do not receive any valid response (ASCII multi-line text followed by OK<CR><LF> ERROR...<CR><LF> then you may alter the baud rate and retry. It is better to first set the maximum supported by port speed and then decrease it until you find a modem or you end up with 110 baud or other reasonable limit.
There is a way to detect if most likely there is nothing connected to the serial port. The idea behind is to detect the frame error that persists during some reasonable time (tens times to receive a byte at selected baud rate), say 2-3sec. To see how enable/disable frame errors detection look at man termios. Howeever, I am not absolutely sure that in the setup you described this will be possible (from within VM), so you have to try.
Also look at this post How to connect to a terminal to Serial-USB device on Ubuntu 10.10?
Be aware, that I found by experience that writing to a serial port to test it can have dire consequences; as my script hung (but only when running on ESXi hypervisor) when trying to test write to a disconnected device
In case it helps, here is a safer way to check
cat /proc/tty/driver/serial | \
grep -v unknown | \
sed 's/^/ttyS/g'
and then check output for ttyS0 for example

What is the difference between IFF_UP and IFF_RUNNING?

These two flags are often set together. What is the difference between them?
From Linux Device Drivers 3:
IFF_UP
This flag is read-only for the driver. The kernel turns it on when the interface is active and ready to transfer packets.
...
IFF_RUNNING
This flag indicates that the interface is up and running. It is mostly
present for BSD compatibility; the kernel makes little use of it. Most
network drivers need not worry about IFF_RUNNING.
Digging a bit deeper, it seems that there is one significant difference:
IFF_RUNNING is supposed to reflect the operational status on a network interface, rather than its administrative one. To provide an example, an Ethernet interface may be brought UP by the administrator (e.g. ifconfig eth0 up), but it will not be considered operational (i.e. RUNNING as per RFC2863) if the cable is not plugged in.
To check if the ethernet cable is really connected to the network You should check IFF_RUNNIG. IFF_UP means that the system allocated the resources for the interface.
Please find detailed code how "ip link show" and "ethtool eth0" checks for link is up here.

Resources