astoeckel / femtosip

Minimal Python SIP implementation ringing phones as a door bell replacement
GNU Affero General Public License v3.0
48 stars 15 forks source link

AttributeError: 'module' object has no attribute 'SIP' on ESP8266 Micropython #2

Closed robertio closed 3 years ago

robertio commented 3 years ago

Hi Andreas,

Thanks you very much for this excellent python SIP module!! - It is hard to find but important lib in VOIP industry. :) Im successfully tried it on my Linux machine and works fine!

But i would like it to use it an more cheaper device. Using ring button from one ESP8266 (ESP01) - microcontroller which cost only 2 USD. How usefull could it to be? :)

ESP devices used are very popular IOT devices. They have Micropython and this Python are works fine in most cases.

I had to install only "logging" library because all the other libraries you used are exists in ESP micropython :)

How to add micropython-logging library to ESP micropython ?: Connect Micropython via webrepl (or repl on serial)

>>>import upip
>>>upip.install("micropython-logging")   

That all. you done.

then i used in this way

>>>import femtosip
>>>sip = femtosip.SIP('doorbell','password','192.168.188.1','5060','door')    

but this is the error message:

Traceback (most recent call last):                                                                              
   File "<stdin>", line 1, in <module>                                                                           
AttributeError: 'module' object has no attribute 'SIP'     
>>>

This is working from my Linux machine.

Do you have any advice?

Best Regards, Robert

robertio commented 3 years ago

Hi Andreas,

I missed an earlier error when I import your library:

>>> import femtosip                                                                                             
Traceback (most recent call last):                                                                              
  File "<stdin>", line 1, in <module>                                                                           
  File "femtosip.py", line 290                                                                                  
SyntaxError: invalid syntax                                                                                     
>>>           

This is the line referred as line 290: from_field = f'<sip:{self.user}@{remote_host}>;tag={tag}'

From this function:


def make_from_field(self, remote_host:str, tag: str):

        from_field = f'<sip:{self.user}@{remote_host}>;tag={tag}'

        if self.display_name:
            from_field = f'"{self.display_name}" ' + from_field

        return from_field

So probably this casues that the SIP module does not work...

Any advise?

astoeckel commented 3 years ago

Thank you for the kind feedback!

I know very little about micropython, but I think that it should be possible to get this to work.

The invalid syntax error like stems from the use of "modern" Python 3.6 format strings. I've pushed an updated version where I removed the use of format strings.

Note that I don't have a SIP setup where I can test this code right now, so please make sure that I didn't break anything ;-) (I added a unit test for the code I touched, but software tends to break in mysterious ways...)

astoeckel commented 3 years ago

Oh, another general comment: it should be possible to strip the code down quite a bit in terms of dependencies.

robertio commented 3 years ago

Hi Andreas,

Thank you very much for this imediate support! Im shocked with your response speed and with the new version. Many many thanks!!

The code works fine with Linux. so you didnt break the code. :)

Micropython accepted the changes and have no syntax error, so the issue resolved! thank you very much.

Unfortunately i have anothre error message:

>>> import femtosip                                                                                             
Traceback (most recent call last):                                                                              
  File "<stdin>", line 1, in <module>                                                                           
MemoryError:                                                                                                    
>>>                 

I assume this is because this microcontroller has too small memory. ESP01 has 1Mbyte only. I hope this causes this this error. Now i try another ESP device. ESP12 has 2 megabyte memory so i try this.

Unfortunately ESP12 device is ~3 USD. too expensive. i wanted to keep the budget under 2USD. i just joking. :) I hope ESP12 will manage memory requirements...

if ESP12 not solve the memory problem - i have to buy ESP32 - but it is too expensive. ~5 USD
i just joking again. :)

Many thanks for your support!! I hope

astoeckel commented 3 years ago

I'm not surprised by the memory error ;-)

As I mentioned above, you should be able to strip down the code by removing dependencies (logging and collections being the simplest). Unfortunately, this is not something I can help you with at the moment, but if you feel adventurous you could tinker around with that yourself.

Of course, getting a device with more memory might be the simplest solution.

I'll leave this issue open; feel free to post an update if you get it to work on any ESP device!

robertio commented 3 years ago

Hi Andreas,

Memory issue seems to me resolved.

So this issue can be closed.

You can see detailes here: https://forum.micropython.org/viewtopic.php?f=16&t=10689

But short summary: ESP01 has 1MB Flash and ~30K free RAM- which allows a roughly few hundred lines of python code. But your amazing code is 559 lines, so on the board on the fly compiler cant handle it.

However there is cross compiler makes called -frozen code - and this resolvs in the most of the case memory error issues. Luckily this was in our case :)

Import femtosip was successfull.

so closing this issue.

I still need your help because i got new error. i open a new issue for that.