Issues measuring the battery level on Wifi1010 + MKR IoT

Hi,

I want to measure the battery level on a WIFI1010 that is on a IotCarrier.
the IoT carrier has a litium battery in it.

So I came to the folowing code:

float readBatteryVoltage() {
  analogReference(AR_EXTERNAL);
  analogReadResolution(10);
  float sensorValue = analogRead(ADC_BATTERY);
  return (sensorValue * 4.208) / 1023.0;
}

However, the sensorValue is always 1023,
so there seem to be something wrong,
and I cannot get where the issue actually is.

any idea?

--
Renaud

you only need to set analog reference and resolution once in set up not on every call to the function. where did you get that code from?

I got the solutin. The pin used as reference when selecting AR_EXTERNAL is not connected to anything in the Mkr IoT board,