Send SMS using SMS cat under fedora25+java1.8+idea

1. Background
    Due to the needs of the project, it is necessary to realize the automatic sending of short messages in the linux+java environment. Naturally, the SMS cat comes to mind. Buy a GSM SMS cat of an unknown brand from Taobao for 170 yuan (the development kit is quite complete, that is, there is no jar package and dll). First of all, through the serial port debugging assistant under Windows, the sending of short messages is realized to confirm that the product is available.
2. Idea
    Because the original project was deployed under Centos, I did test development (fedora25, 64bit) under my laptop first. After Baidu, I found that there are ready-made jar packages for calling -> smslib (thanks to the selfless open source). smslib mainly implements the AT command sending function. At this point, you also need a jar package for serial communication. There are two options: 1 is rxtx, 2 is javacomm. It is said that rxtx is simpler, so rxtx is chosen. The architecture is: the application calls smslib, and then smslib calls rxtx for full functionality.
3. Preparation
    1. First, connect the SMS cat to my linux system. The super terminal tool in linux similar to windows is minicom, so yum install it.
    2. Query the connected device. I am using a USB-to-serial cable, so the device name must be /dev/ttyUSB*. If the computer has a serial port, it should be /dev/ttyS*. In order to test the number of ttyUSBs, I use Minicom test one by one (in fact, my /dev only has one ttyUSB0, which is definitely it). Enter minicom, set the frequency, etc. to enter the command interface, enter the AT command: AT+CPOWD=1, you can see that the device is shut down and restarted, which proves that the device is in good condition and has been connected to the system.
    3. The next step is to install rxtx and smslib. First, the maven dependencies of rxtx are:

<dependency>
    <groupId>org.bidib.jbidib.org.qbang.rxtx</groupId>
    <artifactId>rxtxcomm</artifactId>
    <version>2.2</version>
</dependency>

It can be downloaded directly, but smslib is very pitted and cannot be downloaded directly using the following dependencies:

<dependency>
   <groupId>org.smslib</groupId>
   <artifactId>smslib</artifactId>
   <version>3.5.2</version>
</dependency>

No way, I have to download the jar package of smslib directly, and then manually add it to the local repository of maven:

mvn install:install-file -Dfile=smslib.jar -DgroupId=org.smslib -DartifactId=smslib -Dversion=3.5.2 -Dpackaging=jar

After quoting, I found that the package in intellij idea is always marked with red underline. The method given by csdn is: first delete the maven dependency in the pom, then step back and restore it, and then reimport maven, this method actually worked, but also drunk .
4. Copy the file:

将librxtxSerial.so放到  /usr/java/jdk1.8.0_121/jre/lib/amd64/下(因我的是64bit系统)
将RXTXcomm.jar复制到 /usr/java/jdk1.8.0_121/jre/lib/ext/下

4. I ran the test case excitedly: of course it failed, and the lockfile could not be created due to the error. The official solution is: add the current user (for example, mine is syb) to the lock user group and the uucp user group, but found that I There is no uucp user group in the computer, but only the lock user group, so it is added. You can view it through vi /etc/group, if there is one:

lock:x:54:syb

It proves that the addition is successful, restart the computer. It is found that the top egg is used, or an error is reported. So directly changed the permissions of /run/lock, o+r, o+w. It is found that the error of not reporting uucp×××lockfileXXXplease read INSTALLxxx is gone.
5. I ran the test case, and still reported an error. I probably read it, and the error was about librxtxSerial.so, so I thought maybe my librxtxSerial.so was wrong. Pit, in the case given on the Internet, there is only one librxtxSerial.so file, but I don't know where (probably in csdn) I downloaded another librxtxSerial64.so. Rename this file to librxtxSerial.so (otherwise it will report an error not found), copy it to the original location, and the case runs through. . . . . It seems that librxtxSerial.so also distinguishes 32bit and 64bit, so be sure to download the correct one.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325992446&siteId=291194637