Sending AT commands to SIM900 whilst pppd is active

白昼怎懂夜的黑 提交于 2019-12-01 04:40:02
JSE

Okay I have almost solved this but stuck at the very last hurdle. Thought I would show what I have managed to do as it may help someone else.

I found this other post on stack overflow that lists 3 possible ways to achieve this. I didn't want to be controlling the gprs via AT commands when PPP (in my limited experience) handles this well and easily. The RPi only has one serial port so I couldn't multiplex over multiple serial interfaces.

So that left me with multiplexing over a single serial interface, let's hope the SIM900 supports this. I found here the User Manual on the SIM900 multiplexer which uses the GSM07.10 standard.

I couldn't find much information on how to set up multiplexing but eventually after digging around I found this document on an n_gsm module in the linux kernel. I can just about follow what it was talking about but not enough to write my own program to set up a number of virtual serial ports.

Thankfully after some more scouring of google I found that this extraordinary gentleman has created a C program to use the n_gsm module to set up the virtual serial ports for us.

I downloaded, configured and built the program as per the instructions and tried to load the n_gsm module. Unfortunately the RPi doesn't include the n_gsm module as default so I had to go and build a new kernel with n_gsm added as a module. I followed the instruction on the RPi website which are very good.

For the SIM900 I had to change line 322 to remove the &w of the end of the AT+IPR command. It should know look like:

if (send_at_command(serial_fd, "AT+IPR=115200\r") == -1) errx(EXIT_FAILURE, "AT+IPR=115200: bad response");

I also edited line 128 to sleep(1.5) before trying to read a response as it was sometimes returning an error because it hadn't got a response in time.

So I run the cmux program (with sudo as it needs to create the new /dev/ttyGSM* devices) and it runs through the AT commands, sets the line discipline and creates the new virtual serial devices but when I try and open a serial terminal with screen /dev/ttyGSM1 115200 screen just returns [screen is terminating].

I did sudo fuser /dev/ttyGSM1 which returned nothing so no other process is using it.

I then tried echo AT > /dev/ttyGSM1 which returned -bash: /dev/ttyGSM1: Level 2 halted.

I'm not sure what this is referring to and couldn't find any information on this message. Could it be talking about layer 2 of the OSI model a.k.a the data link layer?

Anyway this is how far I have got. I have decided to put it to one side for now and just use NTP but I hope this helps someone else out. If you do find a solution to this or can suggest something I may have missed please do say. Thanks

i was trying the same and your post helped me very much, finally i've succeeded in doing it following the guide at: https://github.com/guowenxue/embedded_project/tree/master/program/ldattach_gsm0701

but without the patch of the n_gsm driver, in fact doing it the devices 1 to 3 disappeared. with the standard n_gsm.c, ldattach created 63 devices 1 to 4 are working the others not.

i've played al lot with settings, if you have any problem i can post you the entire ldattach.c, anyway i think it will work as standard.

the only drawback now is that when using ppp the bandwidth is so low that most of at commands takes seconds to reply, i'm also trying to get the pop working well, now is really slow.

i think i should lower the bandwidth of the virtual serials as i've not hw flow control (i've also disabled it in ldattach's serial configuration)

le me know if it works for you.

I had the same problem ([screen is terminating], level 2 halted). Take care about the sleep() delay between write() cmux AT command to serial port and setting line discipline via ioctl(). The delay should not be long. Modems have timeout to reset from cmux mode if you don't set line discipline in time. Here are some details and proof.

As for me, I've removed this delay at all.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!