# Reset modem API function

**URL:** <https://forum.legato.io/t/reset-modem-api-function/3233>\
**Category:** Legato Application Framework\
**Created:** [April 25, 2018, 10:09pm UTC](https://forum.legato.io/t/reset-modem-api-function/3233 "2018-04-25T22:09:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mg\_bg](https://avatars.discourse-cdn.com/v4/letter/m/f475e1/32.png) [@mg\_bg](https://forum.legato.io/u/mg_bg)\
**Post date:** [April 25, 2018, 10:09pm UTC](https://forum.legato.io/t/reset-modem-api-function/3233/1 "2018-04-25T22:09:18Z")

</div>

I have been trying to find API to use to reset my modem whenever i have connection issues and unable to connect properly. Currently I’m reseting the whole device by unplugging then plugging back in, but I need to strictly reset the modem in this case. I have found function that gives me info as to why a reset happened:

le\_info\_GetResetInformation() which can give LE\_INFO\_RESET\_USER which mean reset requested by user which makes me believe that there is a function that I can use to reset the modem when required. Any ideas where it is found? I have checked almost all Modem related Apps from Modem Data Control to Modem Info APIs but can’t seem to find it.

In the Modem Demo i have noticed that calling le\_data\_Release(…) and then le\_data\_Request() is their idea of reseting a connection when required. There has to be a function I can call to reset the modem.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [April 26, 2018, 1:09am UTC](https://forum.legato.io/t/reset-modem-api-function/3233/2 "2018-04-26T01:09:21Z")

</div>

have you tried system() API to call “reboot” command? (without sandbox)

---

<div class="post-metadata">

**Author:** ![mg\_bg](https://avatars.discourse-cdn.com/v4/letter/m/f475e1/32.png) [@mg\_bg](https://forum.legato.io/u/mg_bg)\
**Post date:** [April 26, 2018, 2:11pm UTC](https://forum.legato.io/t/reset-modem-api-function/3233/3 "2018-04-26T14:11:49Z")

</div>

No I have not. Will try and let you know. Thanks @jyijyi

---

<div class="post-metadata">

**Author:** ![nvd](https://avatars.discourse-cdn.com/v4/letter/n/82dd89/32.png) [@nvd](https://forum.legato.io/u/nvd)\
**Post date:** [April 26, 2018, 7:53pm UTC](https://forum.legato.io/t/reset-modem-api-function/3233/4 "2018-04-26T19:53:27Z")

</div>

Hey all,

I tried running a system call to `reboot` in a super desperate measure and I don’t think I ever got it working (I think it’s because `reboot` must be called with `sudo` or by a root user). I found using the [Legato watchdog](http://legato.io/legato-docs/latest/c_wdog.html) worked really well for masking problems like this.

The flow I used to achieve this was:

1. Configure the app to expect a watchdog kick roughly on the same interval you’re expecting some data related event (pushing sensor data every 3 minutes in my case). Almost all of this config is in your application definition (`.adef`) file: [Application Definition .adef - Legato Docs](http://legato.io/legato-docs/latest/defFilesAdef.html)
2. Kick the watchdog in `COMPONENT_INIT` to make sure the watchdog starts with the app
3. Send a kick each time the data event happens successfully

If a kick is ever missed, the watchdog will follow the action specified by `watchdogAction` in your corresponding `.adef` file (reboot in my case). This is obviously a very brute force oriented solution, but nonetheless, it works extremely well.

If you’re looking for something a little cleaner, checkout the [le\_mrc interface](http://legato.io/legato-docs/latest/le __mrc__ interface_8h.html#a78bd27d92337e2122320f41bcaa5480f). I haven’t really used this API much, but to my knowledge, some potentially dangerous calls exist in this API, so proceed carefully!

Let me know if some sample code would help clarify any of this and I’ll be happy to provide some.

Cheers!

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [April 27, 2018, 1:29am UTC](https://forum.legato.io/t/reset-modem-api-function/3233/5 "2018-04-27T01:29:45Z")

</div>

I just tried with WP8548 with faultAction in adef file.

* * *

processes:  
{  
envVars:  
{  
LE\_LOG\_LEVEL = DEBUG  
}

```
run:
{
	( hello )
}

maxCoreDumpFileBytes: 512K
maxFileBytes: 512K

faultAction: reboot

```

}

* * *

Once in the code, you have exit(1), the system will reboot.

---

<div class="post-metadata">

**Author:** ![raf](https://avatars.discourse-cdn.com/v4/letter/r/848f3c/32.png) [@raf](https://forum.legato.io/u/raf)\
**Post date:** [April 27, 2018, 2:01am UTC](https://forum.legato.io/t/reset-modem-api-function/3233/6 "2018-04-27T02:01:12Z")

</div>

Hi.

I too needed this some time ago and implemented it much like @jyijyi using `faultAction: reboot` in the adef file. It has the added benefit of allowing the app to run sandboxed and let the supervisor deal with fault recovery.

I went a step further and bundled this functionality up in a separate app with the intention of adding more “custom” APIs for other system functions I might need available to any app running on my system.

Basically, my _utility_ app `.c` file consisted of something like this:

```auto
void sys_util_Reboot()
{
	LE_INFO("User-initiated system reboot...");
	kill(getpid(), SIGINT);
}

COMPONENT_INIT
{
    LE_INFO(" ***Starting System Utility Service***");
}

```

With a simple `.api` file containing:

```auto
/**
 * Function that reboots the system.
 */
FUNCTION Reboot
(
);

```

Hope this helps.  
Raf

---

<div class="post-metadata">

**Author:** ![nvd](https://avatars.discourse-cdn.com/v4/letter/n/82dd89/32.png) [@nvd](https://forum.legato.io/u/nvd)\
**Post date:** [April 27, 2018, 8:44pm UTC](https://forum.legato.io/t/reset-modem-api-function/3233/7 "2018-04-27T20:44:27Z")

</div>

This is a cool solution, thanks for sharing!
