|
129 | 129 |
|
130 | 130 | onMount(() => { |
131 | 131 | applyUrlParameters(); |
132 | | - connectMqtt(mqttAddress); |
| 132 | + connectMqtt(mqttAddress || undefined); |
133 | 133 | if (mockMqtt) { |
134 | 134 | startSineWaveMqttGenerator({ intervalMs: 3000, channel: mqttChannel }); |
135 | 135 | } |
|
196 | 196 | // Subscribe to MQTT data changes |
197 | 197 | $: { |
198 | 198 | const data = getDataByPacket($mqttData) as Record<string, unknown>; |
199 | | - const prefix = getChannelPayload(data, mqttChannel); |
200 | | - if (prefix) { |
| 199 | + // Channel-based lookup (mock: gsw/{channel}/{packetType} → object) falls back to |
| 200 | + // direct packet-name lookup (real: gsw/{PacketName}/{field} → scalar). |
| 201 | + const lookup = getChannelPayload(data, mqttChannel) ?? data; |
| 202 | +
|
| 203 | + const gnsscoordinates = getObjectCaseInsensitive(lookup, "gnsscoordinates"); |
| 204 | + const powermodule = getObjectCaseInsensitive(lookup, "powermodule"); |
| 205 | + const receiverstats = getObjectCaseInsensitive(lookup, "receiverstats"); |
| 206 | + const sensormodule = getObjectCaseInsensitive(lookup, "sensormodule"); |
| 207 | +
|
| 208 | + if (gnsscoordinates || powermodule || receiverstats || sensormodule) { |
201 | 209 | lastTransmission = Date.now(); |
202 | | - const gnsscoordinates = getObjectCaseInsensitive(prefix, "gnsscoordinates"); |
203 | | - const powermodule = getObjectCaseInsensitive(prefix, "powermodule"); |
204 | | - const receiverstats = getObjectCaseInsensitive(prefix, "receiverstats"); |
205 | | - const sensormodule = getObjectCaseInsensitive(prefix, "sensormodule"); |
206 | 210 |
|
207 | 211 | const latitude = getNumberCaseInsensitive(gnsscoordinates, "latitude"); |
208 | 212 | const longitude = getNumberCaseInsensitive(gnsscoordinates, "longitude"); |
|
215 | 219 | battCurrent = getNumberCaseInsensitive(powermodule, "CURR_BATT"); |
216 | 220 | battVoltage = getNumberCaseInsensitive(powermodule, "VOLT_BATT"); |
217 | 221 | receiverSnr = getNumberCaseInsensitive(receiverstats, "SNR", "RCV_SNR", "snr"); |
218 | | - temperature = getNumberCaseInsensitive(sensormodule, "temperature"); |
219 | | - accelX = getNumberCaseInsensitive(sensormodule, "ACCEL_X", "ADX_ACCEL_X", "LSM_ACCEL_X"); |
220 | | - accelY = getNumberCaseInsensitive(sensormodule, "ACCEL_Y", "ADX_ACCEL_Y", "LSM_ACCEL_Y"); |
221 | | - accelZ = getNumberCaseInsensitive(sensormodule, "ACCEL_Z", "ADX_ACCEL_Z", "LSM_ACCEL_Z"); |
| 222 | + temperature = getNumberCaseInsensitive(sensormodule, "temperature", "TEMP_BMP388", "TEMP_MS5611", "TEMP_TMP117"); |
| 223 | + accelX = getNumberCaseInsensitive(sensormodule, "accel_x", "ACCEL_X", "ADX_ACCEL_X", "LSM_ACCEL_X"); |
| 224 | + accelY = getNumberCaseInsensitive(sensormodule, "accel_y", "ACCEL_Y", "ADX_ACCEL_Y", "LSM_ACCEL_Y"); |
| 225 | + accelZ = getNumberCaseInsensitive(sensormodule, "accel_z", "ACCEL_Z", "ADX_ACCEL_Z", "LSM_ACCEL_Z"); |
222 | 226 | } |
223 | 227 | } |
224 | 228 | </script> |
|
0 commit comments