I recommend to generate your SAS token for a longer duration.
Update:
A user voice is being submitted by @Rio, please navigate to When the connection of Azure IoT Hub from Node-RED is disconnected, an error occurs and it cannot be reconnected and vote and comment your requirement in support of asking this feature.
You have to re-create and re-configure the token in Node-Red when it
expires. Please refer to Connect Node-Red to Azure IoT Edge
**via Azure CLI: az iot hub generate-sas-token
Or
via using code as commented by @JD Allen or like using c# shown below,
To get a basic understanding on how SAS Token refresh based on SharedAccessKey , please see this C# code snippet. Please make sure you have IoTHub connection string and deviceId as well. For more reading please refer azure-iot-sdk-csharp
namespace Microsoft.Azure.Devices.Client
{
// Implementing SAS Token refresh based on a SharedAccessKey (SAK).
internal class DeviceAuthenticationWithSakRefresh : DeviceAuthenticationWithTokenRefresh
{
private IotHubConnectionString _connectionString;
public DeviceAuthenticationWithSakRefresh(
string deviceId,
IotHubConnectionString connectionString) : base(deviceId)
{
_connectionString = connectionString;
}
protected override Task<string> SafeCreateNewToken(string iotHub, int suggestedTimeToLive)
{
var builder = new SharedAccessSignatureBuilder()
{
Key = _connectionString.SharedAccessKey,
TimeToLive = TimeSpan.FromSeconds(suggestedTimeToLive),
};
if (_connectionString.SharedAccessKeyName == null)
{
builder.Target = "{0}/devices/{1}".FormatInvariant(
iotHub,
WebUtility.UrlEncode(DeviceId));
}
else
{
builder.KeyName = _connectionString.SharedAccessKeyName;
builder.Target = _connectionString.Audience;
}
return Task.FromResult(builder.ToSignature());
}
}
}
**Also please do refer the Protocol specifics doc.
The Azure IoT SDKs automatically generate tokens when connecting to
the service. In some cases, the Azure IoT SDKs do not support all the
protocols or all the authentication methods.
**Also refer to similar GitHub issues sas token renewal#613, Renew SAS token used by Azure Iot Hub DeviceClient #1127