does IBM Watson IOT platform accepts text/string value? - ibm-cloud

I've successfully sent value of float number=5 from my esp32 to IBM Watson IoT platform and it got captured or received in the board which I created by selecting number in the board but when I'm sending a string or text value instead of number then it was not able to capture so now im confused because while creating the board I've set to text value for capturing or receiving string/text.
Here is the code snippet that I used to send my number value but when I change to string value it does not work so any suggestion:
float number=5;
String text="hello";
String payload = "{\"d\":{\"Name\":\"" DEVICE_ID "\"";
payload += ",\"text\":";
payload += text;
payload += "}}";

I'd think you should enclose your string literal in double-quotes too, here the JSON will be malformed as it will end up as:
{"d":{"Name":"DEVICE_ID","text":hello}}
So the hello text is an invalid JSON token. Should be written as:
String payload = "{\"d\":{\"Name\":\"" DEVICE_ID "\"";
payload += ",\"text\":\"";
payload += text;
payload += "\"}}";

Related

Remove locale from NFC record

I want to pass a text value from my NFC tag to a variable, but want to remove the locale from the text passed to the variable (note, not remove it from the tag).
I am using the nfc_manager package.
Here is the code portion I am using that relates to scanning the tag:
NfcManager.instance.startSession(
onDiscovered: (NfcTag tag) async {
final ndef = Ndef.from(tag);
String tagRecordText = String.fromCharCodes(ndef!.cachedMessage!.records[0].payload);
NfcManager.instance.stopSession();
}
)
The first byte is the length of the characters of the language string
So this should work (my dart is not that good)
var payload = ndef!.cachedMessage!.records[0].payload;
var sub = payload.sublist(payload[0]+ 1);
String tagRecordText = String.fromCharCodes(sub);
The detail specs of a Text Record

How to achieve Base64 URL safe encoding for binary hash string in Powershell?

I am getting the “input” from the server in “Base64-encoded” form as shown in picture.
I need to decode it into its original form of Binary string .i.e original = base64_decode(input) .
concatenate i.e to_be_hash =password (known value) + input.
Hash the concatenated string using SHA-256. i.e binary_hash_str =sha256(to_be_hash).
I need Base64 URL-safe encode the binary hash string above to make it suitable for HTTP requests.
final_hash = base64_url_safe_encode(binary_hash_str)
I am using powershell for this. Can someone guide me how to progress please.
If I understand correctly you would like to send a base64 string as a argument in a url? You can escape the characters that are not acceptable in a url using [uri]::EscapeDataString()
$text = "some text!!"
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text)
$base64 = [System.Convert]::ToBase64String($bytes)
$urlSafeString = [uri]::EscapeDataString($base64)
"Base64 : " + $base64
"urlSafeString : " + $urlSafeString
Base64 : cwBvAG0AZQAgAHQAZQB4AHQAIQAhAA==
urlSafeString : cwBvAG0AZQAgAHQAZQB4AHQAIQAhAA%3D%3D

How to emit socket io variable instead "\"text\"" text notation

Hi
I'm learning to use websocket client in arduino ESP32 board. I can receive and emit text in this form, ""text"" as i can show here.
socketIO.emit("emitevent", "\"this is a message from the client\"");
or
char* Name = "\"Carlos\"";
webSocket.emit("newEmitEvent", Name);
I would like to charge a variable String to send it but i cant find the way. For example,
String Values;
Values = 00:a3:45;
webSocket.emit("newEmitEvent", Values);
But I can't see how to do it,
Can you help me,
please?
Thanks
I've solved with,
Values += """\"";
Values += 00:a3:45;
Values += "," // if i'm in a loop
Values += "\"";
But, it is a clean solution?
Thanks,

How to convert mapped variable into base64 string using Mirth

I have:
Raw xml filled by a select query.This xml transformed into a HL7
message
One of the tags of this xml represents a clob column from a table in
the database
I mapped this data (from edit transformer section) as a variable.
Now I am trying to convert this variable into a base64 string then
replace it in my transformed hl7 message.
5.I tried this conversion on a destination channel which is a javascript writer.
I read and tried several conversion methods like
Packages.org.apache.commons.codec.binary.Base64.encodeBase64String();
I have got only error messages like :
EvaluatorException: Can't find method org.apache.commons.codec.binary.Base64.encodeBase64String(java.lang.String);
Code piece:
var ads=$('V_REPORT_CLOB');
var encoded = Packages.org.apache.commons.codec.binary.Base64.encodeBase64String(ads.toString());
It is pretty clear that I am a newbie on that.How can I manage to do this conversion ?
Here is what I use for Base64 encoding a string with your var substituted.
//Encode Base 64//
var ads = $('V_REPORT_CLOB');
var adsLength = ads.length;
var base64Bytes = [];
for(i = 0; i < adsLength;i++){
base64Bytes.push(ads.charCodeAt(i));
}
var encodedData = FileUtil.encode(base64Bytes);

Storing Special Characters in Windows Azure Blob Metadata

I have an app that is storing images in a Windows Azure Block Blob. I'm adding meta data to each blob that gets uploaded. The metadata may include some special characters. For instance, the registered trademark symbol (®). How do I add this value to meta data in Windows Azure?
Currently, when I try, I get a 400 (Bad Request) error anytime I try to upload a file that uses a special character like this.
Thank you!
You might use HttpUtility to encode/decode the string:
blob.Metadata["Description"] = HttpUtility.HtmlEncode(model.Description);
Description = HttpUtility.HtmlDecode(blob.Metadata["Description"]);
http://lvbernal.blogspot.com/2013/02/metadatos-de-azure-vs-caracteres.html
The supported characters in the blob metadata must be ASCII characters. To work around this you can either escape the string ( percent encode), base64 encode etc.
joe
HttpUtility.HtmlEncode may not work; if Unicode characters are in your string (i.e. &#8217), it will fail. So far, I have found Uri.EscapeDataString does handle this edge case and others. However, there are a number of characters that get encoded unnecessarily, such as space (' '=chr(32)=%20).
I mapped the illegal ascii characters metadata will not accept and built this to restore the characters:
static List<string> illegals = new List<string> { "%1", "%2", "%3", "%4", "%5", "%6", "%7", "%8", "%A", "%B", "%C", "%D", "%E", "%F", "%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17", "%18", "%19", "%1A", "%1B", "%1C", "%1D", "%1E", "%1F", "%7F", "%80", "%81", "%82", "%83", "%84", "%85", "%86", "%87", "%88", "%89", "%8A", "%8B", "%8C", "%8D", "%8E", "%8F", "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97", "%98", "%99", "%9A", "%9B", "%9C", "%9D", "%9E", "%9F", "%A0", "%A1", "%A2", "%A3", "%A4", "%A5", "%A6", "%A7", "%A8", "%A9", "%AA", "%AB", "%AC", "%AD", "%AE", "%AF", "%B0", "%B1", "%B2", "%B3", "%B4", "%B5", "%B6", "%B7", "%B8", "%B9", "%BA", "%BB", "%BC", "%BD", "%BE", "%BF", "%C0", "%C1", "%C2", "%C3", "%C4", "%C5", "%C6", "%C7", "%C8", "%C9", "%CA", "%CB", "%CC", "%CD", "%CE", "%CF", "%D0", "%D1", "%D2", "%D3", "%D4", "%D5", "%D6", "%D7", "%D8", "%D9", "%DA", "%DB", "%DC", "%DD", "%DE", "%DF", "%E0", "%E1", "%E2", "%E3", "%E4", "%E5", "%E6", "%E7", "%E8", "%E9", "%EA", "%EB", "%EC", "%ED", "%EE", "%EF", "%F0", "%F1", "%F2", "%F3", "%F4", "%F5", "%F6", "%F7", "%F8", "%F9", "%FA", "%FB", "%FC", "%FD", "%FE" };
private static string MetaDataEscape(string value)
{
//CDC%20Guideline%20for%20Prescribing%20Opioids%20Module%206%3A%20%0Ahttps%3A%2F%2Fwww.cdc.gov%2Fdrugoverdose%2Ftraining%2Fdosing%2F
var x = HttpUtility.HtmlEncode(value);
var sz = value.Trim();
sz = Uri.EscapeDataString(sz);
for (int i = 1; i < 255; i++)
{
var hex = "%" + i.ToString("X");
if (!illegals.Contains(hex))
{
sz = sz.Replace(hex, Uri.UnescapeDataString(hex));
}
}
return sz;
}
The result is:
Before ==> "1080x1080 Facebook Images"
Uri.EscapeDataString =>
"1080x1080%20Facebook%20Images"
After => "1080x1080 Facebook
Images"
I am sure there is a more efficient way, but the hit seems negligible for my needs.