http post thru multitech gsm modem with python

Home Forums MultiConnect OCG http post thru multitech gsm modem with python

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #2800
    Billy Ashmall
    Participant

    I am trying to do an http post with python and have it use the multitech gsm modem. I have tried multiple ways basically like the following:

    def postData(self, data):

    self.ser.write(‘at+cgdcont=%d,”IP”,”%s”‘ % (NOT EXACTLY WHAT GOES HERE,”a105.2way.net”))

    time.sleep(1)

    print self.ser.readline()

    params = urllib.urlencode({‘@name’: data, ‘@type’: ‘issue’, ‘@action’: ‘show’})

    headers = {“Content-type”: “application/x-www-form-urlencoded”, “Accept”: “text/plain”}

    conn = httplib.HTTPConnection(“localhost”)

    conn.request(“POST”, “https://xxxxxxxxxx/mapresources/sensorprocessing/processpost.aspx”, params, headers)

    response = conn.getresponse()

    print response.status, response.reason

    data = response.read()

    conn.close()

    Can someone please point me in the right direction?

    #4268
    Bryan Tran
    Moderator

    Hi Billy,

    You should make a ppp connection to the internet first and check to see if the ppp link is up, then you can make the POST request.

    Here is a link to show how to make a ppp connection.

    http://www.multitech.net/developer/products/multiconnect-ocg/applications/ppp-peers/

    Regards,

    BT

    #4269
    Billy Ashmall
    Participant

    Hi Bryan,

    I am still having trouble. Here is exactly what my code looks like. Can you please tell me what I am doing wrong? The error I get with this code is “socket.error: [Errno 101] Network is unreachable”

    def postData(self, data, postURL, modemAPN):

    self.ser.write('ATZ')

    self.ser.write('AT+CGDCONT=1,"IP","'+modemAPN+'"')

    time.sleep(1)

    print self.ser.readline()

    self.ser.write('ATD*99#')

    self.ser.write('AT#GPRS=1')

    print self.ser.readline()

    time.sleep(10)

    print 'waited 10 seconds'

    print self.ser.readline()

    self.ser.write('AT#GPRS=1')

    print self.ser.readline()

    conn = httplib.HTTPSConnection(postURL)

    print conn

    params = urllib.urlencode({'name': data, 'AnotherTextbox': 'anything'})

    print params

    headers = {"Content-type": "application/x-www-form-urlencoded"}

    print headers

    conn.request("POST", "/mapresources/sensorprocessing/processpost.aspx", params, headers )

    response = conn.getresponse()

    print response

    #4270
    Bryan Tran
    Moderator

    Hi Billy,

    I was thinking like this:

    1. Update etc/ppp/options, etc/ppp/peers/gsm and gsm_chat file to included your information.

    2. Then either give the command: pppd call gsm & to initiate the ppp connection from the command line or send this command from your python.

    3. Check to see if the ppp is established, by sending a command “ifconfig” and look for the response with ppp0. If there is a ppp0, it means the ppp link is up.

    4. Excute your code block to send a POST to the remote server.

    Regards,

    BT

    #4271
    Bryan Tran
    Moderator

    Hi Billy,

    Also, I am also assuming you are working on the MultiConnect™ OCG-D Open Communications Gateways – Device or the CDP Device.

    Otherwise, what is the model number of the device that you are working with ?

    Regards,

    BT

    #4272
    Billy Ashmall
    Participant

    I am using the mtsmc-g2 connected to the SNAP Connect E10 http://www.synapse-wireless.com/e10. I do not seem to have the directories etc/ppp/options, or etc/ppp/peers/gsm. But When I type pppd in the command line I get [340601.690000] PPP generic driver version 2.4.2 and a bunch of garbled stuff. Is there something I need to do further with the ppp stuff first?

    Thanx,

    ~~~BillyZ

    #4273
    Bryan Tran
    Moderator

    Hi Billy,

    You should contact people at synapse-wireless.com and ask them – how to setup/configure the SNAP Connect E10 device to make a ppp connection using external wireless modem.

    Regards,

    BT

    #4274
    Billy Ashmall
    Participant

    I have made a little headway, but only a little. I have ppp setup and i am now getting a response, but it does not seem to be actually connecting to the internet as I don’t see any data usage on the sim card. It runs thru the process and then terminates the connection almost immediately. Here are the messages that I receive.

    GSM chat

    Dialing…

    Waiting for CONNECT…

    Connected

    Script /usr/sbin/chat -v -t 90 -f /etc/ppp/chat/gprs finished (pid 604), status = 0x0

    Serial connection established.

    using channel 1

    Using interface ppp0

    Connect: ppp0 <–> /dev/ttyACM0

    sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x79ecaa15> <pcomp> <accomp>]

    rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0x79ecaa15> <pcomp> <accomp>]

    rcvd [LCP ConfReq id=0x1 <mru 1500> <asyncmap 0x0> <magic 0x0> <pcomp> <accomp> <auth pap>]

    No auth is possible

    sent [LCP ConfRej id=0x1 <auth pap>]

    rcvd [LCP ConfReq id=0x2 <mru 1500> <asyncmap 0x0> <magic 0x0> <pcomp> <accomp>]

    sent [LCP ConfAck id=0x2 <mru 1500> <asyncmap 0x0> <magic 0x0> <pcomp> <accomp>]

    [ 1343.220000] PPP BSD Compression module registered

    [ 1343.290000] PPP Deflate Compression module registered

    sent [CCP ConfReq id=0x1 <deflate 15> <deflate(old#) 15> <bsd v1 15>]

    sent [IPCP ConfReq id=0x1 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]

    rcvd [LCP TermReq id=0x3]

    LCP terminated by peer

    sent [LCP TermAck id=0x3]

    Modem hangup

    Connection terminated.

    Can you point me in the right direction?

    #4275
    Bryan Tran
    Moderator

    Hi Billy,

    By looking at the log:


    rcvd [LCP ConfReq id=0x1 <mru 1500> <asyncmap 0x0> <magic 0x0> <pcomp> <accomp> <auth pap>]

    No auth is possible


    It looks like to me that, the remote host is sending pap authentication packet and the linux box is saying: No auth is possible.

    *Should check with synapse-wireless.com people to see why the linux box is saying: No auth is possible.

    Regards,

    BT

    #4277
    Billy Ashmall
    Participant

    Ok I’m getting much closer. I now actually get connected to the internet and getting an ip. However I seem to not be able to actually access it. Meaning that I can’t ping. Here is the output. Any help is appreciated.

    # pppd call gprs &

    # GSM chat

    Dialing...

    Waiting for CONNECT...

    Connected

    Script /usr/sbin/chat -v -t 90 -f /etc/ppp/chat/gprs finished (pid 651), status = 0x0

    Serial connection established.

    using channel 2

    Using interface ppp0

    Connect: ppp0 <--> /dev/ttyACM0

    Warning - secret file /etc/ppp/pap-secrets has world and/or group access

    sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0xf94bb3b4> <pcomp> <accomp>]

    rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0xf94bb3b4> <pcomp> <accomp>]

    rcvd [LCP ConfReq id=0x1 <mru 1500> <asyncmap 0x0> <magic 0x2eeef2c0> <pcomp> <accomp> <auth pap>]

    sent [LCP ConfAck id=0x1 <mru 1500> <asyncmap 0x0> <magic 0x2eeef2c0> <pcomp> <accomp> <auth pap>]

    Warning - secret file /etc/ppp/pap-secrets has world and/or group access

    sent [PAP AuthReq id=0x1 user="blank" password="blank"]

    rcvd [PAP AuthAck id=0x1 "Welcome!"]

    Remote message: Welcome!

    PAP authentication succeeded

    sent [CCP ConfReq id=0x1 <deflate 15> <deflate(old#) 15> <bsd v1 15>]

    sent [IPCP ConfReq id=0x1 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]

    rcvd [IPCP ConfReq id=0x1 <addr 192.168.111.111>]

    sent [IPCP ConfAck id=0x1 <addr 192.168.111.111>]

    rcvd [LCP ProtRej id=0x2 80 fd 01 01 00 0f 1a 04 78 00 18 04 78 00 15 03 2f]

    Protocol-Reject for 'Compression Control Protocol' (0x80fd) received

    rcvd [IPCP ConfNak id=0x1 <addr 10.16.146.42> <ms-dns1 63.84.143.13> <ms-dns2 63.84.143.14>]

    sent [IPCP ConfReq id=0x2 <addr 10.16.146.42> <ms-dns1 63.84.143.13> <ms-dns2 63.84.143.14>]

    rcvd [IPCP ConfAck id=0x2 <addr 10.16.146.42> <ms-dns1 63.84.143.13> <ms-dns2 63.84.143.14>]

    local IP address 10.16.146.42

    remote IP address 192.168.111.111

    primary DNS address 63.84.143.13

    secondary DNS address 63.84.143.14

    # ifconfig

    eth0 Link encap:Ethernet HWaddr 00:1C:2C:5C:A0:9C

    UP BROADCAST MULTICAST MTU:1500 Metric:1

    RX packets:0 errors:1 dropped:0 overruns:0 frame:0

    TX packets:1 errors:0 dropped:0 overruns:0 carrier:0

    collisions:0 txqueuelen:1000

    RX bytes:0 (0.0 B) TX bytes:322 (322.0 B)

    Interrupt:21 Base address:0x4000

    lo Link encap:Local Loopback

    inet addr:127.0.0.1 Mask:255.0.0.0

    UP LOOPBACK RUNNING MTU:16436 Metric:1

    RX packets:18 errors:0 dropped:0 overruns:0 frame:0

    TX packets:18 errors:0 dropped:0 overruns:0 carrier:0

    collisions:0 txqueuelen:0

    RX bytes:1296 (1.2 KiB) TX bytes:1296 (1.2 KiB)

    ppp0 Link encap:Point-to-Point Protocol

    inet addr:10.16.146.42 P-t-P:192.168.111.111 Mask:255.255.255.255

    UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1

    RX packets:3 errors:0 dropped:0 overruns:0 frame:0

    TX packets:4 errors:0 dropped:0 overruns:0 carrier:0

    collisions:0 txqueuelen:3

    RX bytes:54 (54.0 B) TX bytes:69 (69.0 B)

    # ping http://www.google.com

    ping: bad address 'www.google.com'

    PS. I also tried pinging 74.125.137.113 and it said pinging with 65 bytes and then just hung there until I CTRL c to get out.

    #4278
    Bryan Tran
    Moderator

    Hi Billy,

    I would look at:

    1. It looks like the eth0 interface does not have an ip address set. Try to set it with command – ifconfig eth0 xxx.xxx.xxx.xxx netmask 255.255.255.0 up. (xxx.xxx.xxx.xxx is private ip like 192.168.1.x).

    To make it permanent, you need to edit configuration file according to your Linux distribution.

    2. resolv.conf file and see if there is an entry for: nameserver 63.84.143.13 in there. If not try to set it.

    3. type ‘route’ command and see if the default is pointing to ppp0 interface.

    4. iptables or firewall and see if it is blocking the pinging command.

    Regards,

    BT

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.