Skip to content

Commit

Permalink
feat: add metrics for Wifi and MQTT status
Browse files Browse the repository at this point in the history
  • Loading branch information
easimon committed Jun 8, 2023
1 parent a675ca8 commit fdd69a2
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@ data class Settings(
@JsonProperty("lng")
val lng: Double,
@JsonProperty("led_status_disable")
val ledStatusDisable: Boolean,
val isStatusLedDisabled: Boolean,
@JsonProperty("fw")
val firmwareVersion: String,

@JsonProperty("device")
val device: Device,
@JsonProperty("cloud")
val cloud: Cloud,

@JsonProperty("ap_roaming")
val apRoaming: ApRoaming,

// Shelly Plug only
@JsonProperty("max_power")
val maxPower: Double?,
@JsonProperty("led_power_disable")
val ledPowerDisable: Boolean?,
val isPowerLedDisabled: Boolean?,
) {

data class Device(
Expand All @@ -39,10 +40,10 @@ data class Settings(
val meterCount: Int,
)

data class Cloud(
data class ApRoaming(
@JsonProperty("enabled")
val enabled: Boolean,
@JsonProperty("connected")
val connected: Boolean
val isEnabled: Boolean,
@JsonProperty("threshold")
val threshold: Int,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ data class Shelly(
@JsonProperty("fw")
val firmwareVersion: String,
@JsonProperty("longid")
val longId: Boolean,
val hasLongId: Boolean,
)
37 changes: 34 additions & 3 deletions src/main/kotlin/click/dobel/shelly/exporter/client/api/Status.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ data class Status(
@JsonProperty("meters")
val meters: List<Meter>,


@JsonProperty("ram_total")
val ramTotal: Long,
@JsonProperty("ram_free")
Expand All @@ -27,12 +26,21 @@ data class Status(
@JsonProperty("update")
val update: Update,

@JsonProperty("wifi_sta")
val wifiSta: WifiSta,

@JsonProperty("mqtt")
val mqtt: Mqtt,

@JsonProperty("cloud")
val cloud: Cloud,

// Following properties available on Plug S only
// val temperature: Double?,
@JsonProperty("overtemperature")
val overTemperature: Boolean?,
@JsonProperty("tmp")
val temperature: Temperature?
val temperature: Temperature?,
) {

data class Relay(
Expand Down Expand Up @@ -79,7 +87,7 @@ data class Status(
@JsonProperty("tF")
val fahrenheit: Double,
@JsonProperty("is_valid")
val isValid: Boolean
val isValid: Boolean,
)

data class Update(
Expand All @@ -88,4 +96,27 @@ data class Status(
@JsonProperty("has_update")
val hasUpdate: Boolean,
)

data class WifiSta(
@JsonProperty("connected")
val isConnected: Boolean,
@JsonProperty("ssid")
val ssid: String,
@JsonProperty("ip")
val ip: String,
@JsonProperty("rssi")
val rssi: Int,
)

data class Mqtt(
@JsonProperty("connected")
val isConnected: Boolean,
)

data class Cloud(
@JsonProperty("enabled")
val isEnabled: Boolean,
@JsonProperty("connected")
val isConnected: Boolean,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,41 @@ class ShellyMetrics(
"cloud.enabled",
"Whether Shelly cloud is enabled.",
tags
) { settings(address)?.cloud?.enabled }
) { status(address)?.cloud?.isEnabled }
boolGauge(
"cloud.connected",
"Whether Shelly cloud is connected.",
tags
) { settings(address)?.cloud?.connected }
) { status(address)?.cloud?.isConnected }

boolGauge(
"wifi.connected",
"Whether Shelly is connected to WIFI.",
tags
) { status(address)?.wifiSta?.isConnected }
gauge(
"wifi.rssi",
"Current Wifi Received Signal Strength Indication (RSSI).",
"dbmw",
tags
) { status(address)?.wifiSta?.rssi }
boolGauge(
"wifi.roaming.enabled",
"Whether AP roaming is enabled.",
tags
) { settings(address)?.apRoaming?.isEnabled }
gauge(
"wifi.roaming.threshold",
"RSSI signal strength value below which the device will periodically scan for better access point.",
"dbmw",
tags
) { settings(address)?.apRoaming?.threshold }

boolGauge(
"mqtt.connected",
"Whether Shelly is connected to MQTT server.",
tags
) { status(address)?.mqtt?.isConnected }

gauge(
"location.latitude",
Expand Down

0 comments on commit fdd69a2

Please sign in to comment.