import time import network import utime import socket import usocket time.localtime() address = '188.179.219.156' port=80 nic = network.Cellular() while not nic.isconnected(): <TAB>print("Waiting to be connected to the cellular network...") <TAB>time.sleep_ms(1500) <TAB><CRLF> <CRLF> <CRLF> print( "Is nic-active?\r\n",nic.active(),"\r\n" ) print("Module is now connected to cellular network") print("Here is a summary of module status:") print("IP address:", nic.ifconfig()[0]) print("SIM card number:", nic.config('iccid')) print("International Mobile Equipment Identity:", nic.config('imei')) print("Network operator:", nic.config('operator')) print("Phone number:", nic.config('phone')) socket_connection = socket.socket() socket_connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) addr = socket.getaddrinfo('188.179.219.156', 80)[0][-1] socket_connection.connect( addr ) time.sleep( 1 ) request = ("GET / HTTP/1.1\r\n Host: 188.179.219.156 \r\n\r\n") bytessent = socket_connection.send(b'GET / HTTP/1.1\r\nHost: 188.179.219.156 \r\n\r\n') print("\r\nSent %d byte GET request to the web server." % bytessent) socket_connection.readline() socket_connection.readline() socket_connection.readline() socket_connection.close() print("Socket closed.") print("Wait", "\r\n") time.sleep( 1 ) print("No Wait", "\r\n") |
>>> >>> >>> import time >>> import network >>> import utime >>> import socket >>> import usocket >>> >>> time.localtime() (2017, 9, 28, 18, 2, 12, 3, 271) >>> >>> address = '188.179.219.156' >>> port=80 >>> >>> nic = network.Cellular() >>> >>> while not nic.isconnected(): ... bytessent port phone socket_connection request nic time message __name__ socket address utime network usocket addr ... print("Waiting to be connected to the cellular network...") ... bytessent port phone socket_connection request nic time message __name__ socket address utime network usocket addr ... time.sleep_ms(1500) ... bytessent port phone socket_connection request nic time message __name__ socket address utime network usocket addr ... ... ... >>> print( "Is nic-active?\r\n",nic.active(),"\r\n" ) Is nic-active? True >>> print("Module is now connected to cellular network") Module is now connected to cellular network >>> print("Here is a summary of module status:") Here is a summary of module status: >>> print("IP address:", nic.ifconfig()[0]) IP address: 10.140.253.103 >>> print("SIM card number:", nic.config('iccid')) SIM card number: 89314404000259777804 >>> print("International Mobile Equipment Identity:", nic.config('imei')) International Mobile Equipment Identity: 357520071462549 >>> print("Network operator:", nic.config('operator')) Network operator: TDC >>> print("Phone number:", nic.config('phone')) Phone number: >>> socket_connection = socket.socket() >>> socket_connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >>> addr = socket.getaddrinfo('188.179.219.156', 80)[0][-1] >>> socket_connection.connect( addr ) >>> time.sleep( 1 ) >>> request = ("GET / HTTP/1.1\r\n Host: 188.179.219.156 \r\n\r\n") >>> bytessent = socket_connection.send(b'GET / HTTP/1.1\r\nHost: 188.179.219.156 \r\n\r\n') >>> print("\r\nSent %d byte GET request to the web server." % bytessent) Sent 42 byte GET request to the web server. >>> socket_connection.readline() b'HTTP/1.1 200 OK\r\n' >>> socket_connection.readline() b'Date: Thu, 28 Sep 2017 16:02:23 GMT\r\n' >>> socket_connection.readline() b'Server: Apache/2.2.29 (Win32) mod_jk/1.2.40\r\n' >>> socket_connection.close() >>> print("Socket closed.") Socket closed. >>> print("Wait", "\r\n") Wait >>> time.sleep( 1 ) >>> print("No Wait", "\r\n") No Wait >>> >>> |