@@ -112,15 +112,33 @@ void ESP32Diagnostics::LogMetricEvent(const MetricEvent & event)
112
112
{
113
113
case ValueType::kInt32 : {
114
114
ChipLogProgress (DeviceLayer, " The value of %s is %" PRId32, event.key (), event.ValueInt32 ());
115
- Diagnostic<int32_t > metric (const_cast <char *>(event.key ()), event.ValueInt32 (), esp_log_timestamp ());
116
- ReturnOnFailure (mStorageInstance ->Store (metric));
115
+
116
+ // Allocate buffers for the diagnostic entry
117
+ char labelBuffer[kMaxStringValueSize ];
118
+ strncpy (labelBuffer, event.key (), kMaxStringValueSize );
119
+ labelBuffer[kMaxStringValueSize - 1 ] = ' \0 ' ;
120
+
121
+ DiagnosticEntry entry = { .label = labelBuffer,
122
+ .intValue = event.ValueInt32 (),
123
+ .type = Diagnostics::ValueType::kSignedInteger ,
124
+ .timestamp = esp_log_timestamp () };
125
+ ReturnOnFailure (mStorageInstance ->Store (entry));
117
126
}
118
127
break ;
119
128
120
129
case ValueType::kUInt32 : {
121
130
ChipLogProgress (DeviceLayer, " The value of %s is %" PRId32, event.key (), event.ValueUInt32 ());
122
- Diagnostic<uint32_t > metric (const_cast <char *>(event.key ()), event.ValueUInt32 (), esp_log_timestamp ());
123
- ReturnOnFailure (mStorageInstance ->Store (metric));
131
+
132
+ // Allocate buffers for the diagnostic entry
133
+ char labelBuffer[kMaxStringValueSize ];
134
+ strncpy (labelBuffer, event.key (), kMaxStringValueSize );
135
+ labelBuffer[kMaxStringValueSize - 1 ] = ' \0 ' ;
136
+
137
+ DiagnosticEntry entry = { .label = labelBuffer,
138
+ .uintValue = event.ValueUInt32 (),
139
+ .type = Diagnostics::ValueType::kUnsignedInteger ,
140
+ .timestamp = esp_log_timestamp () };
141
+ ReturnOnFailure (mStorageInstance ->Store (entry));
124
142
}
125
143
break ;
126
144
@@ -161,8 +179,23 @@ CHIP_ERROR ESP32Diagnostics::StoreDiagnostics(const char * label, const char * g
161
179
{
162
180
VerifyOrReturnError (mStorageInstance != nullptr , CHIP_ERROR_INCORRECT_STATE,
163
181
ChipLogError (DeviceLayer, " Diagnostic Storage Instance cannot be NULL" ));
164
- Diagnostic<char *> trace (const_cast <char *>(label), const_cast <char *>(group), esp_log_timestamp ());
165
- return mStorageInstance ->Store (trace);
182
+
183
+ // Allocate buffers for the diagnostic entry
184
+ char labelBuffer[kMaxStringValueSize ];
185
+ strncpy (labelBuffer, label, kMaxStringValueSize );
186
+ labelBuffer[kMaxStringValueSize - 1 ] = ' \0 ' ;
187
+
188
+ char groupBuffer[kMaxStringValueSize ];
189
+ strncpy (groupBuffer, group, kMaxStringValueSize );
190
+ groupBuffer[kMaxStringValueSize - 1 ] = ' \0 ' ;
191
+
192
+ // Create diagnostic entry
193
+ DiagnosticEntry entry = { .label = labelBuffer,
194
+ .stringValue = groupBuffer,
195
+ .type = Diagnostics::ValueType::kCharString ,
196
+ .timestamp = esp_log_timestamp () };
197
+
198
+ return mStorageInstance ->Store (entry);
166
199
}
167
200
168
201
} // namespace Diagnostics
0 commit comments