Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
Cellular fix to context activation, SARA-R422 corner case: force it. …
Browse files Browse the repository at this point in the history
…(#1041)

A case has turned up where, for SARA-R422, even though the module indicates that it is context activated on the network, i.e. AT+CGACT? returns 1,1, the module's internal clients (e.g. sockets, MQTT and HTTP) do not believe that is so.  What fixes it is to always do an AT+CGACT=1,1 first, i.e. to force context activation.  No idea why this should be necessary; the existing code has been in use for SARA_R422 for several years.

Anyway, this is now done for SARA-R422.
  • Loading branch information
RobMeades authored Nov 10, 2023
1 parent 826e2d1 commit cba2456
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions cell/src/u_cell_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,22 @@ static int32_t getApnStrUpsd(const uCellPrivateInstance_t *pInstance,
return errorCodeOrSize;
}

// Called by activateContext().
static void sendCgact(uAtClientHandle_t atHandle, int32_t contextId,
uAtClientDeviceError_t *pDeviceError)
{
uAtClientLockExtend(atHandle);
uAtClientCommandStart(atHandle, "AT+CGACT=");
uAtClientWriteInt(atHandle, 1);
uAtClientWriteInt(atHandle, contextId);
uAtClientCommandStopReadResponse(atHandle);
// If we get back ERROR then the module wasn't
// ready, if we get back CMS/CME error then
// likely the network has actively rejected us,
// e.g. due to an invalid APN
uAtClientDeviceErrorGet(atHandle, pDeviceError);
}

// Activate context using 3GPP commands, required
// for SARA-R4/R5/R6 and TOBY modules.
// IMPORTANT: this function must run a single uAtClientLock(),
Expand All @@ -1546,13 +1562,27 @@ static int32_t activateContext(const uCellPrivateInstance_t *pInstance,
uAtClientDeviceError_t deviceError;
bool activated = false;
bool ours;
bool cgActCalled;

deviceError.type = U_AT_CLIENT_DEVICE_ERROR_TYPE_NO_ERROR;
uAtClientLock(atHandle);
for (size_t x = 5; (x > 0) && keepGoingLocalCb(pInstance) &&
(errorCode != 0) &&
((deviceError.type == U_AT_CLIENT_DEVICE_ERROR_TYPE_NO_ERROR) ||
(deviceError.type == U_AT_CLIENT_DEVICE_ERROR_TYPE_ERROR)); x--) {
cgActCalled = false;
if (pInstance->pModule->moduleType == U_CELL_MODULE_TYPE_SARA_R422) {
// Note: it seems a bit strange to do this first,
// rather than just querying the +CGACT status,
// but a specific case has been found where SARA-R422
// indicated that it was activated whereas in fact,
// at least for the internal clients (so sockets, HTTP
// and MQTT), it was not. Forcing with AT+CGACT=1,x has
// been shown to fix that. We don't do it in all
// cases as SARA-R41x modules object to that.
sendCgact(atHandle, contextId, &deviceError);
cgActCalled = true;
}
uAtClientLockExtend(atHandle);
uAtClientTimeoutSet(atHandle,
pInstance->pModule->responseMaxWaitMs);
Expand All @@ -1575,18 +1605,12 @@ static int32_t activateContext(const uCellPrivateInstance_t *pInstance,
errorCode = uCellPrivateActivateProfileNoAtLock(pInstance, contextId,
profileId, 5, keepGoingLocalCb);
} else {
if (!cgActCalled) {
// If AT+CGACT wasn't called above, do it now
sendCgact(atHandle, contextId, &deviceError);
}
// Don't hit the module too hard
uPortTaskBlock(2000);
// Help it on its way.
uAtClientLockExtend(atHandle);
uAtClientCommandStart(atHandle, "AT+CGACT=");
uAtClientWriteInt(atHandle, 1);
uAtClientWriteInt(atHandle, contextId);
uAtClientCommandStopReadResponse(atHandle);
// If we get back ERROR then the module wasn't
// ready, if we get back CMS/CME error then
// likely the network has actively rejected us,
// e.g. due to an invalid APN
uAtClientDeviceErrorGet(atHandle, &deviceError);
}
}
uAtClientUnlock(atHandle);
Expand Down

2 comments on commit cba2456

@warasilapm
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you expand more on the edge case that was found which required activation of the context? Just trying to make sure this isn't related to any of our problems.

Tagging @knj11 for his reference.

@RobMeades
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Peter: the issue that required the fix was this one:

#158

Best read from the end backwards I think.

Please sign in to comment.