dl9sec / ArduinoSIP

Arduino SIP library with UDP communications
BSD 3-Clause "New" or "Revised" License
41 stars 19 forks source link

SIP with WiFi and DHCP #2

Closed Schwuuuuup closed 3 years ago

Schwuuuuup commented 3 years ago

Hi,

I tried your code and it works ok. The SipText is not shown or spoken, but I can live with that. Unfortunately not all of my phones show the callers name ("Doorbell") in the display, but that is ok as well.

But I wanted to use DHCP and I struggle to forward the LocalIP to the SIP.init() function:

const char *WiFiIP      = "192.168.111.103";      // WiFi IP of the ESP
[...]
Sip aSip(acSipOut, sizeof(acSipOut));
[...]
void setup() {
[...]
  aSip.Init(SipIP, SipPORT,WiFiIP, SipPORT, SipUSER, SipPW, 15);
}

This works fine but

[...]
Sip aSip(acSipOut, sizeof(acSipOut));
[...]
void setup() {
  [...]

  //after connecting to WiFi via DHCP
  const char *WiFiIP=WiFi.localIP().toString().c_str()
  aSip.Init(SipIP, SipPORT,WiFiIP, SipPORT, SipUSER, SipPW, 15);
}

This doesn't work... it looks as if WiFiIP does not contain the IP I got from DHCP. I'm not very good in C and pointers confuse me.. I guess it has something to do with trying to set a const char* within the setup()...

is there a trick I don't know? is it necessary to have the WiFiIP as a const char* ?

Schönen Gruß TOM

Schwuuuuup commented 3 years ago

Ok, I figured it out... I need const char* WiFiIP=strdup(WiFi.localIP().toString().c_str()); With this I can get the IP from DHCP and put it into the SIP Library