Error "OSError: 118"

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
User avatar
nebenzahl
Posts: 26
Joined: Mon Jul 01, 2019 5:38 pm
Location: Uruguaiana, Brazil
Contact:

Error "OSError: 118"

Post by nebenzahl » Thu Jul 04, 2019 2:38 pm

I need to run a URL and it is giving this error "Error" OSError: 118 " when I execute the command" s.connect (addr) "
Below my code:

import time
import sys
from machine import UART, Pin
import socket

startgprs = Pin (26, Pin.OUT)
ledpower = Pin (19, Pin.OUT)
ledgprs = Pin (23, Pin.OUT)
ledgps = Pin (18, Pin.OUT)
led = Pin (22, Pin.OUT)
phone = UART (1, baudrate = 9200, rx = 16, tx = 17, timeout = 10)

answer = ""
led (0)

ledgprs (0)
ledgps (0)
ledpower (1)

def executes (with):
    res = (phone.read ())
    phone.write (b '% s \ r'% (with))
    time.sleep (0.5)
    res = (phone.read ())
    return res

def command (with):
    res = (phone.read ())
    phone.write (b '% s \ r'% (with))
    return

def connectgprs ():
    startgprs (1)
    time.sleep (3)
    startgprs (0)

def connect gps ():
    time.sleep (3)
    command ('AT + CGNSPWR = 1')

def http_get (host, path):
    print (host)
    print (path)
    addr = socket.getaddrinfo (host, 80) [0] [- 1]
    s = socket.socket ()
    s.connect (addr)
    s.send (bytes ('GET /% s HTTP / 1.0 \ r \ nHost:% \ path \ host \' utf8 '))
    while True:
        date = s.recv (100)
        if data:
            print (str (data, 'utf8'), end = '')
        else:
            break

http_get ('x.x.x.x', 'gps_recebedados.php')


I believe this error is because I can not get on the internet.
Because I'm using an ESP32 and an ev80 SIM808.

I can send SMS through this SIM808 module. But I was not sure if I still surf the internet with him.
In C ++ I can execute this URL.

How can I test this output for the internet.
I'm not going to use wifi in this project.

Thank you!

User avatar
nebenzahl
Posts: 26
Joined: Mon Jul 01, 2019 5:38 pm
Location: Uruguaiana, Brazil
Contact:

Re: Error "OSError: 118"

Post by nebenzahl » Thu Jul 04, 2019 3:24 pm

I added this snippet of code:

gsm=UART(1,rx=16, tx=17, timeout=1000, baudrate=9600)
ppp=network.PPP(gsm)
ppp.active(True)

when I execute these commands, the result is this:

>>> print(ppp.active())
True
>>> print(ppp.status())
None
>>> print(ppp.isconnected())
False
>>> print(ppp.ifconfig())
('0.0.0.0', '0.0.0.0', '255.255.255.255', '0.0.0.0')
>>>


how can I make my esp32 arrive on the internet through a GPRS connection?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Error "OSError: 118"

Post by Roberthh » Thu Jul 04, 2019 4:09 pm

Testing this feature is still on my To-Do-List. But as far as I understood it, one has to establish a conection first with AT-Commands and then attach the ppp channel.

User avatar
nebenzahl
Posts: 26
Joined: Mon Jul 01, 2019 5:38 pm
Location: Uruguaiana, Brazil
Contact:

Re: Error "OSError: 118"

Post by nebenzahl » Thu Jul 04, 2019 5:15 pm

How do I do this?
As I already said, I can communicate with the SIM808, send SMS with AT commands, consult the coordinates of GNSS, everything works fine.
But how would I make an internet connection?
Eng. Luiz Nebenzahl

User avatar
nebenzahl
Posts: 26
Joined: Mon Jul 01, 2019 5:38 pm
Location: Uruguaiana, Brazil
Contact:

Re: Error "OSError: 118"

Post by nebenzahl » Thu Jul 04, 2019 6:18 pm

Victory!
I was able to solve it after some more research.
I want to leave the solution here for someone who needs ...
When working with SIM808 or another module that communicates with AT commands, everything is then by AT commands, even easier.
ESP32 will not have access to the internet, but it will be able to execute AT commands and in fact the SIM that will have the access.

Here below are the commands to execute URL through a SIM808.

from machine import UART, Pin
phone = UART (1, baudrate = 9200, rx = 16, tx = 17, timeout = 10)

phone.write (b '% s \ r'% ('AT + CREG?'))
res = (phone.read ())
print (res)

phone.write (b '% s \ r'% ('AT + SAPBR = 2,1'))
res = (phone.read ())
print (res)


phone.write (b '% s \ r'% ('AT + SAPBR = 1,1'))
res = (phone.read ())
print (res)

time.sleep (5)

phone.write (b '% s \ r'% ('AT + HTTPINIT'))
res = (phone.read ())
print (res)

phone.write (b '% s \ r'% ('AT + HTTPPARA = "URL", "http://gps1.aaaaa.com.br/gps_recebedados.php"'))
res = (phone.read ())
print (res)

phone.write (b '% s \ r'% ('AT + HTTPPARA = "CID", 1'))
res = (phone.read ())
print (res)

phone.write (b '% s \ r'% ('AT + HTTPACTION = 0'))
res = (phone.read ())
print (res)

phone.write (b '% s \ r'% ('AT + HTTPREAD'))
res = (phone.read ())
print (res)

phone.write (b '% s \ r'% ('AT + HTTPTERM'))
res = (phone.read ())
print (res)
Eng. Luiz Nebenzahl

Post Reply