> For the complete documentation index, see [llms.txt](https://docs.heisenware.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.heisenware.com/developers/vrpc/languages/arduino/examples/ir-temperature-agent.md).

# IR Temperature Agent

```cpp
#include <Adafruit_MLX90614.h>
#include <MKRGSM.h>
#include <SPI.h>
#include <vrpc.h>

// APN and GSM data for the SIM used
const char PINNUMBER[] = "<PIN NUMBER>";  // Leave "" when there is no pin
const char GPRS_APN[] = "<APN>";
const char GPRS_LOGIN[] = "<LOGIN>";
const char GPRS_PASSWORD[] = "<PASSWORD>";

// instantiation of utility libraries
GSMClient client;
GPRS gprs;
GSM gsm;
GSMModem modem;
GSMScanner scan;
GSMLocation location;
VrpcAgent agent;
Adafruit_MLX90614 mlx;

// last values cached for location information
float lat = 0;
float lng = 0;
long alt = 0;
long acc = 0;
unsigned long timeout = 0;

void connectGsm() {
  digitalWrite(LED_BUILTIN, HIGH);
  gprs.setTimeout(180000);
  gsm.setTimeout(180000);
  Serial.println("Connecting GSM...");
  while (gsm.begin(PINNUMBER) != GSM_READY ||
         gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) != GPRS_READY) {
    Serial.println("GSM Connection [FAILED]");
    delay(1000);
  }
  Serial.println("GSM Connection [OK]");
  Serial.println(scan.getCurrentCarrier());
  digitalWrite(LED_BUILTIN, LOW);
}

void setup() {
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
  connectGsm();
  location.begin();
  modem.begin();
  String token = modem.getIMEI();
  while (token == NULL) {
    delay(1000);
    token = modem.getIMEI();
  }
  agent.begin(client);
  mlx.begin();
}

void measureLocation() {
  if (location.available()) {
    lat = location.latitude();
    lng = location.longitude();
    alt = location.altitude();
    acc = location.accuracy();
  }
}

void loop() {
  if (gsm.isAccessAlive()) {
    if (gprs.status() != GPRS_READY) {
      if (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) != GPRS_READY) {
        Serial.println("GRPS not ready!");
        delay(1000);
        return;
      }
    }
  } else {
    Serial.println("Reconnect to GSM...");
    connectGsm();
    return;
  }
  if (millis() - timeout > 2000) {
    measureLocation();
    timeout = millis();
  }
  agent.loop();
}

float getObjectTemperature() {
  return mlx.readObjectTempC();
}

float getAmbientTemperature() {
  return mlx.readAmbientTempC();
}

String getGSMCarrier() {
  return scan.getCurrentCarrier();
}

String getSignalStrength() {
  return scan.getSignalStrength();
}

String getLocation() {
  return String(lat, 7) + "," + String(lng, 7);
}

long getAltitude() {
  return alt;
}

long getAccuracy() {
  return acc;
}

VRPC_GLOBAL_FUNCTION(float, getObjectTemperature);
VRPC_GLOBAL_FUNCTION(float, getAmbientTemperature);
VRPC_GLOBAL_FUNCTION(String, getGSMCarrier);
VRPC_GLOBAL_FUNCTION(String, getSignalStrength);
VRPC_GLOBAL_FUNCTION(String, getLocation);
VRPC_GLOBAL_FUNCTION(long, getAltitude);
VRPC_GLOBAL_FUNCTION(long, getAccuracy);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.heisenware.com/developers/vrpc/languages/arduino/examples/ir-temperature-agent.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
