89 lines
2.3 KiB
Python
89 lines
2.3 KiB
Python
#!/usr/bin/python3
|
|
|
|
from test_shared import *
|
|
from lib.sim900.inetgsm import SimInetGSM
|
|
|
|
COMPORT_NAME = "/dev/ttyAMA0"
|
|
BAUD_RATE = 9600
|
|
#logging levels
|
|
CONSOLE_LOGGER_LEVEL = logging.INFO
|
|
LOGGER_LEVEL = logging.INFO
|
|
|
|
def main():
|
|
"""
|
|
Tests HTTP GET and POST requests.
|
|
|
|
:return: true if everything was OK, otherwise returns false
|
|
"""
|
|
|
|
#adding & initializing port object
|
|
port = initializeUartPort(portName=COMPORT_NAME, baudrate=BAUD_RATE)
|
|
|
|
#initializing logger
|
|
(formatter, logger, consoleLogger,) = initializeLogs(LOGGER_LEVEL, CONSOLE_LOGGER_LEVEL)
|
|
|
|
#making base operations
|
|
d = baseOperations(port, logger)
|
|
if d is None:
|
|
return False
|
|
|
|
(gsm, imei) = d
|
|
|
|
inet = SimInetGSM(port, logger)
|
|
|
|
logger.info("attaching GPRS")
|
|
if not inet.attachGPRS("internet", "", "", 1):
|
|
logger.error("error attaching GPRS")
|
|
return False
|
|
|
|
logger.info("ip = {0}".format(inet.ip))
|
|
|
|
#making HTTP GET request
|
|
logger.info("making HTTP GET request")
|
|
|
|
if not inet.httpGet(
|
|
"http://httpbin.org",
|
|
80,
|
|
"/ip"
|
|
):
|
|
logger.error("error making HTTP GET request: {0}".format(inet.errorText))
|
|
return False
|
|
|
|
logger.info("httpResult = {0}".format(inet.httpResult))
|
|
if inet.httpResponse is not None:
|
|
response = str(inet.httpResponse).replace("\n\r", "\n")
|
|
logger.info("response: \"{0}\"".format(response))
|
|
else:
|
|
logger.info("empty response")
|
|
|
|
|
|
if not inet.httpPOST(
|
|
"home.ascorrea.com",
|
|
5010,
|
|
"/upload-file",
|
|
content="image/jpeg",
|
|
parameters=str({"data":open('temp_img_lo.jpg','rb').read()))
|
|
):
|
|
print("[FAILED]")
|
|
return False
|
|
|
|
logger.info("httpResult = {0}".format(inet.httpResult))
|
|
if inet.httpResponse is not None:
|
|
response = str(inet.httpResponse).replace("\n\r", "\n")
|
|
logger.info("response: \"{0}\"".format(response))
|
|
else:
|
|
logger.info("empty response")
|
|
|
|
|
|
logger.debug("detaching GPRS")
|
|
if not inet.dettachGPRS():
|
|
logger.error("error detaching GRPS: {0}".format(inet.errorText))
|
|
return False
|
|
|
|
gsm.closePort()
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
print("DONE")
|