Search found 158 matches

by KJM
Sat Jul 09, 2022 2:06 am
Forum: General Discussion and Questions
Topic: bits to bytes
Replies: 58
Views: 23804

Re: bits to bytes

Thnx for your patient explanations gents, your persistence is appreciated. Jimmo. I'll swap back to a list of 1 & 0 integers for the contact closures. struct represents [1,1,1,1,0] as 0xf0 which is intuitive for me because it works in comfortable 4 bit nibbles. My problem with hex(int('11110') is th...
by KJM
Fri Jul 08, 2022 8:09 am
Forum: General Discussion and Questions
Topic: bits to bytes
Replies: 58
Views: 23804

Re: bits to bytes

You're not paranoid if they really are out to get you! I think the python God's have got it in for me. Checking struct.unpack at the cmd prompt this avo >>> bis='11110' >>> struct.pack('<H', sum(int(bis)*(1<<(i^7)) for i, b in enumerate(bis))) b'\xd0\n' I mean WTF! So I reset the micro & try gain >>...
by KJM
Fri Jul 08, 2022 6:58 am
Forum: General Discussion and Questions
Topic: bits to bytes
Replies: 58
Views: 23804

Re: bits to bytes

tnx for that, I see the error of my ways with trying to use chr, I'll swap to struct. One thing is still puzzling me though. When I was dabbling with chr I'd get bis='1111011111111010' d=int(bis, 2) h=hex(d) r=chr(int(h)) print(r, type(r), len(r), repr(r), type(repr(r)), len(repr(r)))  <class 'str'...
by KJM
Thu Jul 07, 2022 9:13 am
Forum: General Discussion and Questions
Topic: bits to bytes
Replies: 58
Views: 23804

Re: bits to bytes

Something is troubling me Rob. It should take 2 bytes to represent 16 bits. But if I convert my 16 bit string of 1s & 0s to a character with d=int(bis, 2); bys=hex(d); r=chr(int(bys)) & send that over raw lora (without encryption) the receiver says it's received 1 byte. How is it possible to cram 65...
by KJM
Thu Jul 07, 2022 7:02 am
Forum: General Discussion and Questions
Topic: bits to bytes
Replies: 58
Views: 23804

Re: bits to bytes

I double checked this to make sure I got it correct def _Tx(r): s.send(M); m=lora.stats(); print('P(dBm)',m[6], ' sf',m.sftx, ' Tx(ms)',m[7]); print() bis='1111011111111010' d=int(bis, 2); h=hex(d); r=chr(int(h)); print('bys', r, type(r), len(r), 'bytes'); _Tx(r) d=int(bis, 2); h=hex(d); r=(h)[2:7];...
by KJM
Thu Jul 07, 2022 2:00 am
Forum: General Discussion and Questions
Topic: bits to bytes
Replies: 58
Views: 23804

Re: bits to bytes

We've come full circle now, struct.pack was where I started. With struct 16 contacts eg 1111 0111 1111 1010 converts to b'\xf7\xf0' <class 'bytes'> and takes 921 ms to send. But if I use the chr representation 1111 0111 1111 1010 converts to  <class 'str'> and takes 828 ms to send. I'm using a pyco...
by KJM
Thu Jul 07, 2022 12:44 am
Forum: General Discussion and Questions
Topic: bits to bytes
Replies: 58
Views: 23804

Re: bits to bytes

I hear you martincho but the lora radio won't let me use bytes, it has to be a buffer protocol. So the only way I can compress my 16 contact closures into a buffer protocol entity is to convert them to type string with hex and send that 2 byte string.
by KJM
Wed Jul 06, 2022 8:56 am
Forum: General Discussion and Questions
Topic: bits to bytes
Replies: 58
Views: 23804

Re: bits to bytes

After reading the learned comments I thought I had a handle on bytes & the different ways python displays them. But I still managed to fall at the first hurdle. If I do bis='1111011111111010'; d=int(bis, 2); r=hex(d); print(r, repr(r)) then send r to the lora modem all good 0xf7fa '0xf7fa' but if I ...
by KJM
Wed Jul 06, 2022 12:27 am
Forum: ESP8266 boards
Topic: REPL Prompt very slow
Replies: 5
Views: 2275

Re: REPL Prompt very slow

What ide you using Michael? I've used the 8286 on Thonny, uPyCraft & Atom & always found the repl fairly fast.
by KJM
Wed Jul 06, 2022 12:23 am
Forum: General Discussion and Questions
Topic: Digital Clock drift
Replies: 5
Views: 1830

Re: Digital Clock drift

You should see what they get up to in deepsleep. I've seen free running neon tube oscillators keep better time.