Move snprintf to work with any architecture.

This commit is contained in:
Nathan Seidle
2021-12-12 21:46:36 -07:00
parent 1b3f033792
commit 356a43ded6
@@ -93,7 +93,8 @@ void setup()
Serial.print(F("Connecting to local WiFi"));
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(F("."));
}
@@ -102,7 +103,8 @@ void setup()
Serial.print(F("WiFi connected with IP: "));
Serial.println(WiFi.localIP());
while (Serial.available()) Serial.read();
while (Serial.available())
Serial.read();
}
void loop()
@@ -110,7 +112,8 @@ void loop()
if (Serial.available())
{
beginClient();
while (Serial.available()) Serial.read(); //Empty buffer of any newline chars
while (Serial.available())
Serial.read(); //Empty buffer of any newline chars
}
Serial.println(F("Press any key to start NTRIP Client."));
@@ -126,7 +129,8 @@ void beginClient()
Serial.println(F("Subscribing to Caster. Press key to stop"));
delay(10); //Wait for any serial to arrive
while (Serial.available()) Serial.read(); //Flush
while (Serial.available())
Serial.read(); //Flush
while (Serial.available() == 0)
{
@@ -181,13 +185,14 @@ void beginClient()
String strEncodedCredentials = b.encode(userCredentials);
char encodedCredentials[strEncodedCredentials.length() + 1];
strEncodedCredentials.toCharArray(encodedCredentials, sizeof(encodedCredentials)); //Convert String to char array
snprintf(credentials, sizeof(credentials), "Authorization: Basic %s\r\n", encodedCredentials);
#else
//Encode with nfriendly library
int encodedLen = base64_enc_len(strlen(userCredentials));
char encodedCredentials[encodedLen]; //Create array large enough to house encoded data
base64_encode(encodedCredentials, userCredentials, strlen(userCredentials)); //Note: Input array is consumed
#endif
snprintf(credentials, sizeof(credentials), "Authorization: Basic %s\r\n", encodedCredentials);
}
strncat(serverRequest, credentials, SERVER_BUFFER_SIZE);
strncat(serverRequest, "\r\n", SERVER_BUFFER_SIZE);
@@ -221,7 +226,8 @@ void beginClient()
int responseSpot = 0;
while (ntripClient.available())
{
if (responseSpot == sizeof(response) - 1) break;
if (responseSpot == sizeof(response) - 1)
break;
response[responseSpot++] = ntripClient.read();
if (strstr(response, "200") > 0) //Look for '200 OK'
@@ -263,7 +269,8 @@ void beginClient()
{
//Serial.write(ntripClient.read()); //Pipe to serial port is fine but beware, it's a lot of binary data
rtcmData[rtcmCount++] = ntripClient.read();
if (rtcmCount == sizeof(rtcmData)) break;
if (rtcmCount == sizeof(rtcmData))
break;
}
if (rtcmCount > 0)
@@ -278,12 +285,7 @@ void beginClient()
}
//Provide the caster with our current position as needed
if (ntripClient.connected() == true
&& transmitLocation == true
&& (millis() - lastTransmittedGGA_ms) > timeBetweenGGAUpdate_ms
&& ggaSentenceComplete == true
&& ggaTransmitComplete == false
)
if (ntripClient.connected() == true && transmitLocation == true && (millis() - lastTransmittedGGA_ms) > timeBetweenGGAUpdate_ms && ggaSentenceComplete == true && ggaTransmitComplete == false)
{
Serial.print(F("Pushing GGA to server: "));
Serial.println(ggaSentence);
@@ -315,7 +317,8 @@ void beginClient()
int responseSpot = 0;
while (ntripClient.available())
{
if (responseSpot == sizeof(response) - 1) break;
if (responseSpot == sizeof(response) - 1)
break;
response[responseSpot++] = ntripClient.read();
if (strstr(response, "200") > 0) //Look for '200 OK'