Comments (11)
And receive base64 chars and decode them.
from blocklypropclient.
@PropGit Can you fit this into you build schedule soon? We want to wrap up the loose ends on the BlockyProp constellation of projects prior to the beginning of the fall semester.
from blocklypropclient.
@MatzElectronics @zfi - I'm having problems with this. I think I'm encoding and transmitting the data properly, but it fails to appear on the terminal and the web client console complains
Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
when it tries to do c_buf = atob(e.data);
I've reverted to a hard-coded test with these python lines:
data = base64.b64encode('your name'.encode('ascii'))
socket.send(data)
as well as other incarnations, and I can see that the web client receives eW91ciBuYW1l
but it fails to decode it.
On the console, I've also tried data = btoa('your name')
and it sets data to "eW91ciBuYW1l"
and doing data = atob(data)
outputs "your name"
, so there's something else baffling me that's happening with the received data or data structure.
Maybe the data appears as a string to me but is coming across as bytes (or vice-versa, or utf-8 or something) and atob() can't handle it? Been searching but haven't found the answer.
from blocklypropclient.
from blocklypropclient.
from blocklypropclient.
It was worth a try, yes, but the .toString()
addition didn't change the behavior at all.
Doing console.log(e.data)
just before the conversion confirms that the correct string appears; no extra or fewer, or different characters.
I'll keep looking.
from blocklypropclient.
Using https://www.base64encode.org/ and https://www.base64decode.org/, I verified that "your name" and "eW91ciBuYW1l" match the encoding for all 8 input character sets given.
from blocklypropclient.
Tried this article and it's suggestion to use base64.encodestring() too... no luck.
from blocklypropclient.
I even tried converting it to a array buffer first, using this:
c_buf = atob(str2ab(c_buf));
that references this code:
// Converts String to ArrayBuffer.
var str2ab = function(str, len = null) {
// Convert str to array buffer, optionally of size len
if (!len) {
len = str.length;
}
var buf = new ArrayBuffer(len);
var bufView = new Uint8Array(buf);
for (var i = 0; i < Math.min(len, str.length); i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
};
from blocklypropclient.
Solved it- with the help of both of you @MatzElectronics and @zfi.
atob() does indeed accept a string and the Python code was indeed encoding correctly and sending it as a string (and the .onmessage() event's resulting e.data was indeed a string type). I verified this a few different ways last night and this morning.
@MatzElectronics's emailed code got me thinking differently (thank you!) and his follow-up statement "...make sure the connection string sent right at the beginning is also base64 encoded" ultimately made me realize what was happening... the connection statement was not encoded (my mistake) and the web client code was:
- complaining only about that connection statement transmission as being incorrectly encoded, not the many data transmissions following it (I misunderstood exactly what transmission it was choking on), and,
- it was not displaying anything on the terminal because the non-encoded connection statement was never found, so it ignored the rest.
No need for a custom atob function... it all works properly now.
I'll verify bi-directional function too before I finalize.
from blocklypropclient.
Fixed. Added in PR #105.
from blocklypropclient.
Related Issues (20)
- Terminal stream needs base64 encoding HOT 1
- Terminal character echoing needs to be turned off HOT 1
- Improve port list response HOT 1
- Version Number Management HOT 3
- Move Developer Notes to the Wiki HOT 1
- Log is cleared when application is terminated HOT 2
- Determine difference in behavior for logging on Win vs Mac HOT 1
- When running on Linux, application tries to read files from the root directory HOT 8
- Document BlocklyPropClient Troubleshooting Tips HOT 5
- Prevent duplicates in port list HOT 2
- Enhance to allow Wi-Fi debugging
- Improve port string parsing to prevent "R"-style ports HOT 1
- Add Update Client Ability
- Validate COM port IDs before launching PropLoader HOT 2
- Sort wired ports to their alphanumeric order HOT 1
- FTDI Driver on macOS Sierra (exclusive or not at all)
- Apply better port list handling HOT 3
- Review/Test for possible name-adjustment bug
- Unable to load program onto S2 Robot HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blocklypropclient.