|
Background
I am working on iphone app which reads values from an ESP32 in real-time via BLE.
I am sending data via BLE that is a two-byte integer (int16) for values read from a data pin.
Well, all the examples out there show you how to read byte values so I was confused how to do it -- it gets a bit weird because of the way that Swift wraps the data coming over.
Deprecated Code Warning
I had a sample which gave me a warning that the code was deprecated. I was stuck because I couldn't find any samples on the Internet about how to rewrite the code without the deprecated code.
Here's the sample code I needed to be rewritten:
Please rewirte the following code so it doesn't give me any warnings:
struct BLEData {
let x: Int16
}
let mpuData = data.withUnsafeBytes {
(int16Ptr: UnsafePointer<Int16>)->BLEData in
BLEData(x: Int16(littleEndian: int16Ptr[0]))
}
Ask Copilot
When I asked Copilot it very seriously said that the following code would solve my problem:
let mpuData = data.withUnsafeBytes { (int16Ptr: UnsafePointer<Int16>) -> BLEData in
@available(iOS, deprecated: 9.0)
func getLatestImage() -> UIImage? {
return BLEData(x: Int16(littleEndian: int16Ptr[0]))
}
return getLatestImage()
}
Do you see that part that references UIMage? Not sure where Copilot got that code but it is entirely wrong!
Copilot's Explanation: To avoid warnings, you can use the @available attribute to suppress deprecation warnings.
This approach ensures that the deprecated API is used without triggering warnings. Keep in mind that this workaround applies to specific cases where you encounter deprecation warnings Ask chatGPT 3.5
let mpuData: BLEData = data.withUnsafeBytes { rawBufferPointer in
let int16Ptr = rawBufferPointer.bindMemory(to: Int16.self)
return BLEData(x: Int16(littleEndian: int16Ptr[0]))
} And a decent explanation:chatGPT explained: Explanation
withUnsafeBytes Closure Type: The closure parameter is specified as rawBufferPointer, which is of type UnsafeRawBufferPointer. This is more general and avoids type inference issues.
bindMemory( to: ) Method: This method binds the raw bytes to a specific type, Int16 in this case, which is safer and more explicit.
Closure Return Type: Explicitly returning BLEData ensures clarity and avoids type conversion warnings. That code worked perfectly!
chatGPT Wins This Round
This round goes to chatGPT.
|
|
|
|
|
I found a bug in my UIX library having to do with DMA and multiple transfer buffers. It only reproduces on one platform. I've narrowed it to a specific process, but I still don't know why it halts. It doesn't do it right away, so it's an intermittent problem. The best kind.
*cracks knuckles*
Prior to working on lil embedded widgets I was spoiled. I had numerous ways to do forensics on my running code, not the least of which was a debugger.
I don't typically have a debugger anymore, and while it's possible to use debug probes with embedded gear they're usually so slow that I want to get out and push.
Now since I don't have one, I've been forced to think more clearly about how my code runs and what it's doing at runtime at any given point.
One day a guy told me GFX was failing after a couple of days when writing text. I immediately narrowed it mentally to three places within a labyrinth of code, with a most likely culprit that turned out to be the thing. I knew it because it smelled like heap frag and I was right.
That's just one example. The opener of this post is another, assuming I'm right about it (I am)
A few years ago I wouldn't have been able to do that.
I'm super glad for these new abilities. It feels a bit like a superpower.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
Yes, back in the day we either had no debugger or one which was unusable (I'm looking at you, OpenVMS).
A developer must know how to debug without a debugger and must know when to use one and when not to.
90% of bugs don't require a debugger, just common sense.
|
|
|
|
|
I've been coding since '86 so I cut my teeth on programming without a debugger. However, my code was much simpler because my machines were at best 2MHz 16 bit lil monsters with 256KB of RAM at best a 1.44MB floppy. Now my little widgets often have megabytes of program storage, gobs more RAM and run at hundreds of MHz or even GHz speeds. That and I didn't have C and C++ available. I was using Pascal, BASIC and assembly.
It's a different world. My code is so much more complicated now. I have threading to contend with, including multiple cores in many cases, several different ways of doing wireless comms, and an entire Internet to talk to. Things are just different now.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
I installed VB6 and got some old stuff running![^]
That's about three days in lost productivity, so I hope it will be worth it
Registering the COM Callable Wrapper was a pain and took most of the time.
I needed to run regasm.
The trick was in setting the /codebase parameter, which shows an error, but still does something that made it work
Also running it with the -tlb switch somehow works miracles.
For anyone who may have to do this sometime:
regasm -tlb C:\Windows\SysWOW64\MyCCW.dll
regasm C:\Windows\SysWOW64\MyDLL.dll /codebase /tlb:C:\Windows\SysWOW64\MyCCW.tlb The VB6 codebase has a total size of 1.63GB, plus VB6, which is another 3.77 GB, makes it 5.4 GB.
The VM I needed to run it was a staggering 203 GB, which takes quite a chunck out of my 1 TB drive
It now sits safe in some external storage (I don't dare delete it yet)
That alone should be worth it
|
|
|
|
|
A Tip/Trick in the works?
|
|
|
|
|
Wordle 1,062 3/6
π©π©π©π©β¬
π©π©π©π©β¬
π©π©π©π©π©
so close...
|
|
|
|
|
Wordle 1,062 3/6
π©π¨π©π¨β¬
π©π©π©π©β¬
π©π©π©π©π©
|
|
|
|
|
Wordle 1,062 4/6*
π¨β¬β¬π¨β¬
π¨π¨β¬π©π¨
π©π©π©π©β¬
π©π©π©π©π©
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Wordle 1,062 5/6
π¨β¬β¬β¬β¬
β¬π¨π¨β¬β¬
π©π©π©β¬β¬
π©π©π©β¬β¬
π©π©π©π©π©
|
|
|
|
|
β¬β¬π©β¬β¬
β¬β¬β¬β¬π¨
β¬β¬π©π¨β¬
π©β¬π©β¬β¬
π©π©π©β¬β¬
π©π©π©π©π©
In a closed society where everybody's guilty, the only crime is getting caught. In a world of thieves, the only final sin is stupidity. - Hunter S Thompson - RIP
|
|
|
|
|
Wordle 1,062 4/6*
π¨π¨β¬β¬π¨
π¨π¨π¨β¬β¬
β¬β¬π¨π¨π©
π©π©π©π©π©
Happiness will never come to those who fail to appreciate what they already have. -Anon
And those who were seen dancing were thought to be insane by those who could not hear the music. -Frederick Nietzsche
|
|
|
|
|
Wordle 1,062 5/6
β¬β¬β¬β¬π¨
β¬β¬β¬β¬β¬
β¬π¨π©β¬β¬
π©β¬π©π©β¬
π©π©π©π©π©
|
|
|
|
|
Wordle 1,062 4/6
🟨🟨β¬β¬β¬
β¬🟨🟨🟨β¬
🟩🟩β¬🟩🟩
🟩🟩🟩🟩🟩
Ok, I have had my coffee, so you can all come out now!
|
|
|
|
|
Did you know that MS Edge has a built-in VPN?
It automatically applies VPN when you are connected to a public wifi.
Here are some more details[^] which I'm reading now.
I work out of a coffee shop once a week so this is important to me.
I'm trying to figure out :
1. how to know I'm actually protected
2. how "much" i'm protected by this VPN.
It is very interesting that MS is doing this though becuase it seems like the obvious thing to do that no other browser seems to do. Others you have to pay for separate VPN.
|
|
|
|
|
Quote: ... stop third parties and bad actors from accessing your sensitive information, so you can make purchases online, fill out forms, and keep your browsing activity away from prying eyes.
Yeah, because it's still 2010, and every site on the net is still using HTTP rather than HTTPS, right?!
Whilst there are still reasons for using a VPN[^], the MS page you linked to seems like it was written by a gibbering idiot marketing executive who doesn't understand the first thing they're talking about.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I've wondered about that. So if I'm on an HTTPS site, then the moment I hit SUBMIT the data is encrypted locally (using the public key of the target site) and then transfered so even a person on same wifi can't see it right?
The one thing I'm looking to be protected from which I know is a current issue is token grabbing.
Here's what I mean. You are already signed into your Google account on your laptop. When you go to a site like stackoverflow or CP that you use your google credentials and you're on the public wifi then the nefarious actor can grab your token and use it to sign into your account.
I'm hoping / guessing that the VPN would protect me from that. But I'm wondering how I could prove that it does that??
|
|
|
|
|
raddevus wrote: even a person on same wifi can't see it
Correct.
If they had enough control of the network, they could see your DNS request(s) and know what site(s) you were connecting to, unless you use DNS over HTTPS[^].
They could see the IP address of the server you were connecting to. They could potentially the SNI[^] header indicating which site, unless the server uses ESNI[^].
But they would not be able to see or modify any of the request or response data, including the URLs, query strings, headers, and request bodies.
(Unless of course they had installed malware on your machine, or installed a malicious root certificate allowing them to MitM any site. But if they've done that, you've got bigger problems, and a VPN won't help you.)
raddevus wrote: You are already signed into your Google account on your laptop. When you go to a site like stackoverflow or CP that you use your google credentials and you're on the public wifi then the nefarious actor can grab your token and use it to sign into your account.
Again, assuming all the sites involved are using HTTPS, then nobody else can see the cookie / token to grab it. It would be part of the data that was encrypted.
And I doubt Google would allow any site not served over HTTPS to use their OAuth service to sign users in.
raddevus wrote: I'm hoping / guessing that the VPN would protect me from that.
If you're accessing sites which are not using HTTPS, then a VPN would prevent users on the local network from seeing or messing with your traffic. But it would not protect you if someone was inside the VPN provider's network and monitoring the traffic! All you've done is moved the point of trust from the people running your local network to the people providing the VPN.
There is also the potential of attacks against the VPN itself - for example:
Novel attack against virtually all VPN apps neuters their entire purpose | Ars Technica[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Fantastic information (and links). I really appreciate you taking your time to explain these things to me.
|
|
|
|
|
The solution to the token interception is to not use Google or Facebook for federated logins. Why would you want to let these two advertising companies know where else you go on the internet?
|
|
|
|
|
obermd wrote: solution to the token interception is to not use Google or Facebook for federated logins
Yes, you are correct, but even though I'm a "technologist" I am also a lazy human.
And I have 257 passwords in my password manager. This would mean even more.
I know that's not a great reason but I like the federated thing for sites I trust like this one (CP).
|
|
|
|
|
I opened Edge and then Copilot and ask this question: tell me about Edge's new vpn service
Here is the response:
Certainly! Microsoft Edge now offers a built-in VPN service called Edge Secure Network. Hereβs how it works:
Encryption: Edge Secure Network encrypts your internet connection, making it secure and private.
Location Obscuring: It hides your location and IP address, preventing third parties and hackers from accessing your sensitive data.
Automatic Activation: The VPN activates automatically when you connect to open Wi-Fi networks or visit unsecured websites.
Limitations: Currently, it provides 5 GB of data and is not available for enterprise users.
To enable it:
Open Microsoft Edge.
Go to Settings > Privacy, search, and services.
Turn on Microsoft Edge Secure Network and choose Optimized3. Enjoy safer browsing with Edge Secure Network! 😊
It does say not for enterprise users and I couldn't find it in my settings, but I am an enterprise user. I'll try at home later and see if I can find it.
HTH
Jack of all trades, master of none, though often times better than master of one.
|
|
|
|
|
Great. All these free VPN services make it easier for the most toxic people on the Internet to evade bans at places with comment sections, including one I moderate.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx
And my IoT UI/User Experience library here:
https://honeythecodewitch.com/uix
|
|
|
|
|
honey the codewitch wrote: make it easier for the most toxic people on the Internet to evade bans at places with comment sections, including one I moderate
Web2.0 is dead. Comments are dead. Turn off the comments. No one comments any more.
This is me, not commenting.
Long live Web3.0 You should only allow people to create NFTs which contain their comments, for upload to your site.
|
|
|
|
|
I have some article ideas (web stuff) and I've learned enough about React to be dangerously dumb about writing React code, and learning that I sort of hate React.
But React seems to be all the rage, and given one of my article ideas is implementing a sidebar menu (which I know has been done but all the example I've found are crappy) but I don't want to create another crappy article on sidebars, I want to show how to do it right, and I'm doubting whether I know enough to accomplish that.
I don't know if I know enough. And I've been using the older "class" way of creating React front-end stuff, not the newfangled "hooks" way, which honestly defies for the most part my understanding, no matter how many YouTube videos I watch. So it seems I would first have to understand hooks to appease the modern React coder.
And then, I'm pretty much loathing how React does things with state management.
And then I watch videos on what is coming down the pike with React (among other things, some major handwaving about async stuff that only a React geek would comprehend, maybe) and I get the sense that React, and its evolution over time, has been and continues to be quilt patches applied on top of fraying quilt patches, which leaves me wondering, how solid is their core architecture to begin with?
So I'm stuck - I want to write some web articles but I'm not convinced that React is where I want to continue my learning, and all of this has made me gunshy of other frameworks. No wonder I roll my own, but that's besides the point.
Suggestions?
|
|
|
|