# Accessing inbound messages

**URL:** <https://discuss.blues.com/t/accessing-inbound-messages/849>\
**Category:** Notecard API\
**Created:** [May 27, 2022, 10:46pm UTC](https://discuss.blues.com/t/accessing-inbound-messages/849 "2022-05-27T22:46:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brecky](https://avatars.discourse-cdn.com/v4/letter/b/bc79bd/32.png) [@brecky](https://discuss.blues.com/u/brecky)\
**Post date:** [May 27, 2022, 10:46pm UTC](https://discuss.blues.com/t/accessing-inbound-messages/849/1 "2022-05-27T22:46:32Z")

</div>

Hi,

I’m trying to test out whether I can change the sampling interval of an MCU connected to a sensor. I can see on the debug console that we got the MCU/carrier to pick up a number from the server (in this test case ‘456’ which I put in ‘env.sampling\_interval’), but I haven’t been able to figure out how to get that number into a variable so that I can use it in my code. I’m pretty sure I’m just not understanding the API correctly.

This is what I have that isn’t working:

```auto
if (J *req = (notecard.newRequest("env.get"))) {
      J *rsp = notecard.requestAndResponse(req);
      notecard.deleteResponse(rsp);

      int sampling_interval = JGetNumber(rsp, "sampling_interval");
      Serial.print("sampling interval: ");
      Serial.println(sampling_interval); 
 }

```

output:  
15:25:47.895 → {“req”:“env.get”}  
15:25:48.029 → {“body”:{“sampling\_interval”:“456”,"\_\<…\>"}}  
15:25:48.029 → sampling interval: 0

---

<div class="post-metadata">

**Author:** ![Alec](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@Alec](https://discuss.blues.com/u/Alec)\
**Post date:** [May 27, 2022, 11:42pm UTC](https://discuss.blues.com/t/accessing-inbound-messages/849/2 "2022-05-27T23:42:15Z")

</div>

Hi,

This is what I’m using. “envVariable” is the name of the variable and “defaultValue” is returned if the variable is not found or an error occurred.

```auto
float ncGetEnv(char* envVariable, float defaultValue) {
  float rValue=defaultValue;
  J *req = notecard.newRequest("env.get");
  if (req != NULL) {
    JAddStringToObject(req, "name", envVariable);
    J *rsp = notecard.requestAndResponse(req);
    if (rsp != NULL) {
      if (!notecard.responseError(rsp)) {
        if (JIsPresent(rsp, "text")) rValue=JAtoN(JGetString(rsp, "text"),NULL);
      }
      notecard.deleteResponse(rsp);
    }
  }
  return rValue;
}

```

---

<div class="post-metadata">

**Author:** ![brecky](https://avatars.discourse-cdn.com/v4/letter/b/bc79bd/32.png) [@brecky](https://discuss.blues.com/u/brecky)\
**Post date:** [May 28, 2022, 12:51am UTC](https://discuss.blues.com/t/accessing-inbound-messages/849/3 "2022-05-28T00:51:15Z")

</div>

That works perfectly!

Thank you so much,  
Brecky
