@@ -252,8 +252,25 @@ struct AppConfig
252252 meshcore_config.meshcore_channel_name [sizeof (meshcore_config.meshcore_channel_name ) - 1 ] = ' \0 ' ;
253253 prefs.getBytes (" mc_ch_key" , meshcore_config.secondary_key , sizeof (meshcore_config.secondary_key ));
254254
255- mesh_protocol = static_cast <chat::MeshProtocol>(
256- prefs.getUChar (" mesh_protocol" , static_cast <uint8_t >(chat::MeshProtocol::Meshtastic)));
255+ uint8_t mesh_protocol_raw = prefs.getUChar (" mesh_protocol" , 0xFF );
256+ if (mesh_protocol_raw == static_cast <uint8_t >(chat::MeshProtocol::Meshtastic) ||
257+ mesh_protocol_raw == static_cast <uint8_t >(chat::MeshProtocol::MeshCore))
258+ {
259+ mesh_protocol = static_cast <chat::MeshProtocol>(mesh_protocol_raw);
260+ }
261+ else
262+ {
263+ int legacy_protocol = prefs.getInt (" mesh_protocol" ,
264+ static_cast <int >(chat::MeshProtocol::Meshtastic));
265+ if (legacy_protocol == static_cast <int >(chat::MeshProtocol::MeshCore))
266+ {
267+ mesh_protocol = chat::MeshProtocol::MeshCore;
268+ }
269+ else
270+ {
271+ mesh_protocol = chat::MeshProtocol::Meshtastic;
272+ }
273+ }
257274
258275 // Load device name
259276 size_t len = prefs.getBytes (" node_name" , node_name, sizeof (node_name) - 1 );
@@ -402,6 +419,8 @@ struct AppConfig
402419 prefs.putBool (" mc_tx_en" , meshcore_config.tx_enabled );
403420 prefs.putString (" mc_ch_name" , meshcore_config.meshcore_channel_name );
404421 prefs.putBytes (" mc_ch_key" , meshcore_config.secondary_key , sizeof (meshcore_config.secondary_key ));
422+ // Remove first so legacy key type mismatches cannot block updating this value.
423+ prefs.remove (" mesh_protocol" );
405424 prefs.putUChar (" mesh_protocol" , static_cast <uint8_t >(mesh_protocol));
406425
407426 // Save device name
0 commit comments