Skip to content

Commit 90575a5

Browse files
committed
added logic to *type* output lines/strings in the system. Allows output *writers* to determine what actions to take with the data - deal with headers, deal with mime types ...etc
1 parent 002e4f2 commit 90575a5

File tree

8 files changed

+38
-25
lines changed

8 files changed

+38
-25
lines changed

src/Flux/flxCoreInterface.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ class flxDataEditor
4444
};
4545

4646
// Define an interface for output of log information.
47+
typedef enum
48+
{
49+
flxLineTypeNone = 0,
50+
flxLineTypeData = 1,
51+
flxLineTypeHeader = 2,
52+
flxLineTypeMime = 4
53+
} flxLineType_t;
4754

4855
class flxWriter
4956
{
@@ -55,14 +62,18 @@ class flxWriter
5562
};
5663
virtual void write(int) = 0;
5764
virtual void write(float) = 0;
58-
virtual void write(const char* value, bool newline)=0;
65+
virtual void write(const char* value, bool newline, flxLineType_t type) = 0;
66+
virtual void write(const char* value, bool newline)
67+
{
68+
write(value, newline, flxLineTypeData);
69+
};
5970
virtual void write(std::string &value, bool newline)
6071
{
61-
write(value.c_str(), newline);
72+
write(value.c_str(), newline);
6273
}
6374
virtual void write(const char * value)
6475
{
65-
write(value, true);
76+
write(value, true);
6677
}
6778
virtual void write(std::string &value)
6879
{

src/Flux/flxIoTAWS.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@ class flxIoTAWS : public flxMQTTESP32SecureCore<flxIoTAWS>, public flxWriter
4040
{
4141
// noop
4242
}
43-
virtual void write(const char * value, bool newline)
43+
virtual void write(const char * value, bool newline, flxLineType_t type)
4444
{
45-
if (!value)
45+
// no data? Or is this a header line (not sure why it would be - we just want JSON)
46+
if (!value || type != flxLineTypeData)
4647
return;
4748

4849
// Wrap the value with the structure required to update the device shadow
4950
char szBuffer[strlen(value) + sizeof(kAWSUpdateShadowTemplate)];
5051
snprintf(szBuffer, sizeof(szBuffer), kAWSUpdateShadowTemplate, value);
51-
flxMQTTESP32SecureCore::write(szBuffer, false);
52+
flxMQTTESP32SecureCore::write(szBuffer, false, type);
5253
}
5354

5455
bool initialize(void)

src/Flux/flxIoTAzure.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,13 @@ class flxIoTAzure : public flxMQTTESP32SecureCore<flxIoTAzure>, public flxWriter
8383
// noop
8484
}
8585
//---------------------------------------------------------------------
86-
virtual void write(const char *value, bool newline)
86+
virtual void write(const char *value, bool newline, flxLineType_t type)
8787
{
88-
if (!value || !_connected)
88+
// value? Connected? Data line?
89+
if (!value || !_connected || type != flxLineTypeData)
8990
return;
9091

91-
flxMQTTESP32SecureCore::write(value, false);
92+
flxMQTTESP32SecureCore::write(value, false, type);
9293
}
9394

9495
//---------------------------------------------------------------------

src/Flux/flxIoTHTTP.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ template <class Object> class flxIoTHTTPBase : public flxActionType<Object>
244244

245245
//----------------------------------------------------------------------------
246246
// flxWriter interface method
247-
virtual void write(const char *value, bool newline)
247+
virtual void write(const char *value, bool newline, flxLineType_t type)
248248
{
249-
// if we are not connected, ignore
250-
if (!_isEnabled || !_canConnect || !value || _url.length() < 10)
249+
// if we are not connected, ignore, bad url skip, we want json, so no headers
250+
if (!_isEnabled || !_canConnect || !value || _url.length() < 10 || type != flxLineTypeData)
251251
return;
252252

253253
if (!_wifiClient)
@@ -341,10 +341,10 @@ class flxIoTHTTP : public flxIoTHTTPBase<flxIoTHTTP>, public flxWriter
341341
// noop
342342
}
343343
//---------------------------------------------------------------------
344-
virtual void write(const char *value, bool newline)
344+
virtual void write(const char *value, bool newline, flxLineType_t type)
345345
{
346346

347-
flxIoTHTTPBase<flxIoTHTTP>::write(value, false);
347+
flxIoTHTTPBase<flxIoTHTTP>::write(value, false, type);
348348
}
349349
};
350350
#endif

src/Flux/flxIoTMachineChat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class flxIoTMachineChat : public flxIoTHTTPBase<flxIoTMachineChat>, public flxIW
8080
serializeJson(jsonOutput, strOutput);
8181

8282
// post to machine chat.
83-
flxIoTHTTPBase<flxIoTMachineChat>::write(strOutput.c_str(), false);
83+
flxIoTHTTPBase<flxIoTMachineChat>::write(strOutput.c_str(), false, flxLineTypeData);
8484
}
8585
}
8686
};

src/Flux/flxIoTThingSpeak.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class flxIoTThingSpeak : public flxMQTTESP32SecureCore<flxIoTThingSpeak>, public
130130
// Topic is based on the channel...
131131

132132
// send this payload to thingspeak
133-
flxMQTTESP32SecureCore::write(buffer.c_str(), false);
133+
flxMQTTESP32SecureCore::write(buffer.c_str(), false, flxLineTypeData);
134134
}
135135
}
136136

src/Flux/flxMQTTESP32.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,12 @@ template <class Object, typename CLIENT> class flxMQTTESP32Base : public flxActi
195195

196196
//----------------------------------------------------------------------------
197197
// flxWriter interface method
198-
virtual void write(const char *value, bool newline)
198+
virtual void write(const char *value, bool newline, flxLineType_t type)
199199
{
200200

201201
// Should we continue?
202-
// enabled? Have a value to send?
203-
if (!_isEnabled || !value)
202+
// enabled? Have a value to send? We only deal with JSON - just the data
203+
if (!_isEnabled || !value || type != flxLineTypeData)
204204
return;
205205

206206
// If we lost the connection to the broker, try to reconnect...
@@ -287,9 +287,9 @@ class flxMQTTESP32 : public flxMQTTESP32Base<flxMQTTESP32, WiFiClient>, public f
287287
{
288288
// noop
289289
}
290-
void write(const char *value, bool newline)
290+
void write(const char *value, bool newline, flxLineType_t type)
291291
{
292-
flxMQTTESP32Base::write(value, newline);
292+
flxMQTTESP32Base::write(value, newline, type);
293293
}
294294
};
295295

@@ -591,9 +591,9 @@ class flxMQTTESP32Secure : public flxMQTTESP32SecureCore<flxMQTTESP32Secure>, pu
591591
{
592592
// noop
593593
}
594-
void write(const char *value, bool newline)
594+
void write(const char *value, bool newline, flxLineType_t type)
595595
{
596-
flxMQTTESP32Base::write(value, newline);
596+
flxMQTTESP32Base::write(value, newline, type);
597597
}
598598
};
599599
#endif

src/Flux/flxOutput.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ class flxOutputFormat
9191
_Writers.erase(iter);
9292
}
9393

94-
void outputObservation(const char *szBuffer)
94+
void outputObservation(const char *szBuffer, flxLineType_t type = flxLineTypeData)
9595
{
9696

9797
for (auto writer : _Writers)
98-
writer->write(szBuffer);
98+
writer->write(szBuffer, true, type);
9999
}
100100

101101
private:

0 commit comments

Comments
 (0)