ARMmbed / mbed-os-example-cellular

This is an example based on mbed-os cellular APIs that demonstrates a TCP or UDP echo transaction with a public echo server.
Apache License 2.0
20 stars 43 forks source link

Not working on SDT64B #137

Closed heejungPark closed 4 years ago

heejungPark commented 5 years ago

Hi, I tested this code on our device(SDT64B). But it is not connected to server and I got a log(Log.txt). I don't know what the problem is. Could you please check this log and answer me? Thanks. Here are my code(main.cpp, mbed_app.json). mbed-os-example-cellular.zip

heejungPark commented 5 years ago

I found one thing. I modify PIN number from "1234" to "0000". But same result...

heejungPark commented 5 years ago

For more detail log, "cellular.debug-at" is changed to true. Here is the log(Log2.txt).

ciarmcom commented 5 years ago

ARM Internal Ref: IOTCELL-1981

mirelachirica commented 5 years ago

@heejungPark Logs are showing that there are 2 PDP contexts defined: +CGD CONT: 1,"IPV6","lte-internet..sktelecom.com","0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0",0,0,0,0 +CGDCONT: 2,"IP" ,"lte-internet.sktelecom.com","0.0.0.0",0,0,0,0

This might cause the problem.

In order to delete existing PDP contexts you could try adding following "one time" routine to your application, before connect:

ATHandler *at = CellularDevice::get_default_instance()->get_at_handler();
    for (int i=0; i<7; i++) {
        at->cmd_start("AT+CGDCONT=");
        at->write_int(i);
        at->cmd_stop();
        at->resp_start();
        at->resp_stop();
        at->clear_error();
    }
 CellularDevice::get_default_instance()->release_at_handler(at);

Let us know if that is helping the case or not.

heejungPark commented 5 years ago

@mirelachirica

For reference, we are using BG96 as Cat.M1 module. With this module, we additionally tested two projects except this code(mbed-os-example-cellular).

  1. https://os.mbed.com/users/hkjung/code/WIZnet-IoTShield-BG96-Ping => Success
  2. https://os.mbed.com/users/hkjung/code/mbed-os-example-cellular-BG96 => Fail

Because of the result of first project, I think BG96 module could be normal. Actually I refer to the second project for setting mbed_app.json of mbed-os-example-cellular. May I know whether this json file has a problem? And, as you mentioned, I add that code before calling connect(). But I got a almost same results. Please confirm this log and source code (file.zip).

Thanks.

mirelachirica commented 5 years ago

May I know whether this json file has a problem?

Can you try removing "target.features_add": ["LWIP"] from json file?

heejungPark commented 5 years ago

I tried it but same results...

mirelachirica commented 5 years ago

I just noticed in the log file that the clearing of contexts before connect wasn't working since the modem was not ready to receive AT commands yet. So it has to be done later:

MBED_ASSERT(iface);
iface->attach(cellular_callback);
void cellular_callback(nsapi_event_t ev, intptr_t ptr)
{
    // support for testing in non-blocking mode and step by step
    if (ev >= NSAPI_EVENT_CELLULAR_STATUS_BASE && ev <= NSAPI_EVENT_CELLULAR_STATUS_END) {
        cell_callback_data_t *ptr_data = (cell_callback_data_t *)ptr;
        cellular_connection_status_t cell_ev = (cellular_connection_status_t)ev;
        if (cell_ev == CellularSIMStatusChanged && ptr_data->error == NSAPI_ERROR_OK &&
            ptr_data->status_data == CellularDevice::SimStateReady) {

                ATHandler *at = CellularDevice::get_default_instance()->get_at_handler();
                for (int i=0; i<7; i++) {
                    at->cmd_start("AT+CGDCONT=");
                    at->write_int(i);
                    at->cmd_stop();
                    at->resp_start();
                    at->resp_stop();
                    at->clear_error();
                }
                CellularDevice::get_default_instance()->release_at_handler(at);
        }
    }
}

Reminder: this should be done/needed only ONCE.

heejungPark commented 5 years ago

I used your second way on my project. The result is same but a little message is different. Here are my files. Please refer it. File.zip

mirelachirica commented 5 years ago

Now from log it can be seen that old contexts were deleted correctly. But QIACT still fails. From WIZnet-IoTShield-BG96-Ping example I see the context is setup with QICSGP not the standard CGDCONT. So what could be tried is replace in AT_CellularContext::set_new_context(...)

    _at.cmd_start("AT+CGDCONT=");
    _at.write_int(cid);
    _at.write_string(pdp_type_str);
    _at.write_string(_apn);

with

  _at.cmd_start("AT+QICSGP=");
    _at.write_int(cid);
    _at.write_int(2); //ipv4v6 in WIZnet-IoTShield-BG96-Ping, 1 would be value for ipv4
    _at.write_string(_apn);
    _at.write_string("");
    _at.write_string("");
    _at.write_int(0);

Does it make any difference?

heejungPark commented 5 years ago

Yes, it makes a difference. Now I can see "Connection Established." message. But the next step could be fail. Here are the logs(Log5.txt). Thanks.

heejungPark commented 5 years ago

I have a additional question. Why are the old contexts from WIZnet-IoTShield-BG96-Ping example left? To set this module to initial state, is there a way that I delete all contexts in module? Thanks.

mirelachirica commented 5 years ago

But the next step could be fail. Here are the logs(Log5.txt).

The DNS name resoving fails. You could try one of the following:

mirelachirica commented 5 years ago

To set this module to initial state, is there a way that I delete all contexts in module?

Other than suggested above, no. There is no API at the moment to do this.

heejungPark commented 5 years ago

Is it right as follows? Please check this(Log6.txt). Thanks. image image

mirelachirica commented 5 years ago

I cannot access the Log6.txt file.

mirelachirica commented 5 years ago

Is it right as follows?

Yes, the modifications look correct. It can be tried with both 1 and 2 values for QICSGP, once the echo server is set in json to be the IP address.

heejungPark commented 5 years ago

Sorry please access again? Log6.txt

mirelachirica commented 5 years ago

Log6 shows again 2 contexts. Can you enable the clearing of contexts code?

heejungPark commented 5 years ago

Oh sorry, I attached log again. Log7.txt

mirelachirica commented 5 years ago

Now old contexts are deleted but the context setup with QICSGP and type 1(IPv4) fails to activate with QIACT. So please change back QICSGP to use type 2(IPv4v6) and leave the echo test as IP address.

heejungPark commented 5 years ago

I changed code as follows.

image

image

So this try successes. Here is the log. Log8.txt.

mirelachirica commented 5 years ago

Good!

So it seems the DNS resolving doesnt work for some reason. From the log when DNS solving is taking place, I can see that there is no responses coming from any of the DNS servers where requests are sent: 8.8.8.8, 209.244.0.3, 84.200.69.80.

Is it possible that you could try with WIZnet-IoTShield-BG96-Ping example to call getIpAddressByName_BG96(...), to see if there is some generic problem of comunication with these DNS servers, in the cellular network you are conncted to?

heejungPark commented 5 years ago

Sorry, it is not the answer about your request.

First, I checked a array named pdp_type_str[]. This array is always "IP". I don't know why modem_supports_ipv4 is true and modem_supports_ipv6 is false?

For test, when I set "IPV6" or "IPV4V6" by force, it is working well as follows. So, I think it could be another solution if user can control modem_supports_ipv6 to true. Is there a way that user can control that variable?

image

image

mirelachirica commented 5 years ago

The IPv6 support for the modem has to be set in: QUECTEL_BG96.cpp: cellular_properties[AT_CellularBase::PROPERTY_MAX] ... 0, // PROPERTY_IPV6_STACK -> 1, // PROPERTY_IPV6_STACK ...

mirelachirica commented 5 years ago

For test, when I set "IPV6" or "IPV4V6" by force, it is working well as follows.

What works well? The context activation with CGDCONT, so no need for QICSGP?

heejungPark commented 5 years ago

Ah, I see, I found that. Then, is it not care that I change value of this cellular_properties?

"IPV6" and "IPV4V6", both is working well.

mirelachirica commented 5 years ago

Then, is it not care that I change value of this cellular_properties?

No problem. It should be changed according with the modem support.

"IPV6" and "IPV4V6", both is working well.

What works well, the context activation without need for QICSGP?

The echo server is still set as IP address?

heejungPark commented 5 years ago

You can see it in a part of code and serial log, I used CGDCONT. PROPERTY_IPV6_STACK of cellular_properties is set 1, it could be no problem to use CGDCONT.

And echo server is still set as IP address(52.215.34.155). when echo.mbedcloudtesting.com, it is not working.

mirelachirica commented 5 years ago

Ok, very good finding. Please let me know if you have time to check the DNS resolving as I proposed earlier. Thanks.

heejungPark commented 5 years ago

Sorry but I don't know what I should input parameters of getIpAddressByName_BG96(...).

mirelachirica commented 5 years ago

First parameter should be the name to be resolved: "echo.mbedcloudtesting.com" and second parameter should be a buffer where the IP address is saved:

char ipstr[50];
getIpAddressByName_BG96("echo.mbedcloudtesting.com", ipstr);
heejungPark commented 5 years ago

The result with WIZnet-IoTShield-BG96-Ping example is as follows. ( ipstr: 2A05:D018:21F:3800:3164:2A5C:75B3:970B )

[MAIN] Waiting for Cat.M1 Module Ready...

[MAIN] BG96 ready

[MAIN] System Init Complete

[MAIN] WIZnet IoT Shield for Arm MBED
[MAIN] LTE Cat.M1 Version
[MAIN] =================================================
[MAIN] >> Target Board: WIoT-QC01 (Quectel BG96)
[MAIN] >> Sample Code: Ping Test
[MAIN] =================================================

[BG96] Turn Echo OFF success

[BG96] USIM Status: READY

[BG96] Network Status: attached

[BG96] Checking APN...

[BG96] APN Check Done

[BG96] Activate a PDP Context

[MAIN] ipstr: 2A05:D018:21F:3800:3164:2A5C:75B3:970B

[MAIN] [Ping] Host: 8.8.8.8

[BG96] 8.8.8.8: 569

[BG96] 8.8.8.8: 569

[BG96] 8.8.8.8: 569

[BG96] 8.8.8.8: 569

[MAIN] [Ping] Host: www.google.com

[BG96] www.google.com: 0,"2404:6800:4004:808:0:0:0:2004",32,107,255

[BG96] www.google.com: 0,"2404:6800:4004:808:0:0:0:2004",32,160,255

[BG96] www.google.com: 0,"2404:6800:4004:808:0:0:0:2004",32,169,255

[BG96] www.google.com: 0,"2404:6800:4004:808:0:0:0:2004",32,150,255

[BG96] Deactivate a PDP Context
0Grit commented 5 years ago

@mirelachirica Any further comments on the log provided?

mirelachirica commented 5 years ago

Last log proves that in your network/setup, DNS resolving works when proprietary command AT+QIDNSGIP is used. We have to check and consider having support for this command.

heejungPark commented 5 years ago

Okay thanks. It seems that USIM card of this module may be discarded. If it is true, could it be a reason of our problem?

mirelachirica commented 5 years ago

@heejungPark can you check if changing in QUECTEL_BG96_CellularStack::create_socket_impl(...): _at.write_string("127.0.0.1"); -> _at.write_string("0:0:0:0:0:0:0:1"); helps the DNS resolving?

This seems to be the case in following PR: https://github.com/ARMmbed/mbed-os/pull/10473

DanielDmlee commented 5 years ago

Hi @mirelachirica, Already @heejungPark and I had talked about this patch. We guess this problem was from an expired SIM card. As far as I know, heejungPark try to changing SIM card via seller.

AriParkkila commented 4 years ago

Closing as resolved.