These are chat archives for esp8266/Arduino

13th
Jun 2018
Ash
@ashthespy
Jun 13 2018 00:00
that's for you to decide :-) but no harm
den har
@denman0000_gitlab
Jun 13 2018 00:02
@ashthespy you mentioned single js to access all esp's .. do you perhaps have a link i could read and follow for that .. great concept :-) is it a esp8266 bot network
can the be pushed a central config and or autonomous ?
@ashthespy and @moose4621 .. OOOOOOMMMMMMGGGGGGGG its working
yaaaaaaaaaaaaaaaaaaaaaaaaaay
Ash
@ashthespy
Jun 13 2018 00:04
Hmm, I would have to google. What I have are multiple ESPNodes, all running a WebSocket server. Then I have one single 'FrontEnd' that is pure client side javascript. This 'FrontEnd' shows what all nodes are connected and capabilities and status
den har
@denman0000_gitlab
Jun 13 2018 00:04
wooop woop woop
Ash
@ashthespy
Jun 13 2018 00:04
Nice! :-)
den har
@denman0000_gitlab
Jun 13 2018 00:04
indeed
so thats the solution
and wow its fast :-)
Ash
@ashthespy
Jun 13 2018 00:05
What was the issue? you hadn't linked the files?
den har
@denman0000_gitlab
Jun 13 2018 00:05
that sounds pretty damn cool ash .. would love a demo vid/perv
Ash
@ashthespy
Jun 13 2018 00:05
Yep - these 2$ boards + all the time the devs have put in makes it quite a breeze.
den har
@denman0000_gitlab
Jun 13 2018 00:06
yes seems you have to specify each .js file you need exposed
Ash
@ashthespy
Jun 13 2018 00:06
Ah - will keep that in mind for the future!
den har
@denman0000_gitlab
Jun 13 2018 00:06
i love these little esp's more and more
Ash
@ashthespy
Jun 13 2018 00:06
I don't think I have a demo/vid/write up
but I am sure someone has one out there ;-)
den har
@denman0000_gitlab
Jun 13 2018 00:07
i was using arduino and nrf24L01+ but this is a much nicer solution
Ash
@ashthespy
Jun 13 2018 00:07
Yep + cheaper!
den har
@denman0000_gitlab
Jun 13 2018 00:07
well a pow wow sometime if you have a mo would be funky , I'm not a coder but love tech
yes re cheaper
just wish they would put proper track spacing in
Ash
@ashthespy
Jun 13 2018 00:08
MQTT would probably be a better option for most homeautomation tasks..
den har
@denman0000_gitlab
Jun 13 2018 00:08
and for the dude who ever release schamtics for a stabel cheap and cool AC to 3,3 v tiny PSU .. well he/she has my respect :-)
Ash
@ashthespy
Jun 13 2018 00:09
but I wanted to dip my toes into the forbidden world of JavaScript
den har
@denman0000_gitlab
Jun 13 2018 00:10
you know the home automation scene has its place but it seems there way too much of a strong reliance upon the internet for placing ghe control server in ..problem is when there no link to interent for whatever reason .. and goodbye control
the brain should be decentralized ... unlike most systems being created for IOT
den har
@denman0000_gitlab
Jun 13 2018 00:11
and/or mirrored
yes re voltage ... think very tiny and safe
Ash
@ashthespy
Jun 13 2018 00:12
I agree - I keep all my home automation stuff strictly inside my LAN
check out the link - have had good success with them!
den har
@denman0000_gitlab
Jun 13 2018 00:12
there are available but cost is high .. and the cheap ones are not safe at all in fact they are time bombs /firecrackers
den har
@denman0000_gitlab
Jun 13 2018 00:13
I've had my eye on those for ages .. but they're very costly .. especially when having to convert currency and then for transport too .. gets crazy
Ash
@ashthespy
Jun 13 2018 00:14
You should be able to find them way cheaper at aliexpress/ebay
usually ~2-3$
den har
@denman0000_gitlab
Jun 13 2018 00:16
cool will keep watching .. i have been using the tiny chinese ones from inside mobile chargers
about 1,5 USD
Ash
@ashthespy
Jun 13 2018 00:17
I normally get non isolated ones but to 5v and then have a small ldo on board.
But to pass the girlfriend approval it needs to look more 'polished' up :P
den har
@denman0000_gitlab
Jun 13 2018 00:18
hahha yes the WAF - Wife Acceptance Factor
the 'government' at home
have you seen sonoff ?
Ash
@ashthespy
Jun 13 2018 00:20
Yep they have some nice hackable stuff
as far as i know it's an esp8266 inside ..
Ash
@ashthespy
Jun 13 2018 00:21
Yes - there exists an entire ecosystem of firmware for them
den har
@denman0000_gitlab
Jun 13 2018 00:21
problem i find is their software .. it's web based .. and i want home based under my exclusive control
den har
@denman0000_gitlab
Jun 13 2018 00:21
yep :-) good link
so i think i will adapt for my surrounds and just buy the modules and hack em a little
Ash
@ashthespy
Jun 13 2018 00:22
That should help you cut out the evil cloud ;-)
den har
@denman0000_gitlab
Jun 13 2018 00:23
esp8266 servers well as a smartswitch controller too to controll the classic 300 and 433 MHZ switches too
so esp then can act as the central distribution point to all smart plugs :-)and more
imagine what a dashboard then
a home NOC :-)
Ash
@ashthespy
Jun 13 2018 00:24
I still haven't settled on the perfect physical switch replacement.
den har
@denman0000_gitlab
Jun 13 2018 00:24
dont replace .... encompass them all
use what you have
Ash
@ashthespy
Jun 13 2018 00:25
Something that you don't have to pull out your phone to turn on/off
den har
@denman0000_gitlab
Jun 13 2018 00:25
use google alexa or siri and talk to it :-)
Ash
@ashthespy
Jun 13 2018 00:25
Lol. that negates the "within the LAN" principle
den har
@denman0000_gitlab
Jun 13 2018 00:26
or a dartboard lol .. but use throwing knives .. the right throw hits the lights target etc
yes somthing like that ..
solve on - the light is toggled!
den har
@denman0000_gitlab
Jun 13 2018 00:27
you could just add in an LDR to the esp
Haha indeed ..Edison and Volta covered the easy part the rest of the world have been battling for years to find ways to switch and control it :-)
Ash
@ashthespy
Jun 13 2018 00:29
I made a small board with teh ESP12 + a TTP223 works quite well for my needs. Need to polish it up now!
den har
@denman0000_gitlab
Jun 13 2018 00:29
cool .. I'm using 12F and tiny relays all 3,3V
and design was NRF
before that was PIC ..now switching all to esp i think ..
first step is ESP as controller then will replace TX/RX on each
@ashthespy ok man I am outta here .. need a few hours sleep before early meeting .. chat soon .. will pop in and see if you're here .. if you seem me yell and say howdy ..catch you on the flipside :-) TY for the help
Chris Dalby
@moose4621
Jun 13 2018 09:57
@ashthespy This uint array stuff is doing my head in!
Ash
@ashthespy
Jun 13 2018 12:20
@moose4621 Where are you stuck?
Chris Dalby
@moose4621
Jun 13 2018 20:53
After reading more about unsigned integers etc, on the server I tried to go to uint32-t but I am lost as to how to define it.
void sendSettings()
{
uint32_t payload[] = {setpointVariable, targetGroundSpeed};
webSocket.broadcastBIN(payload, sizeof(payload));
}

Arduino: 1.8.5 (Linux), Board: "WeMos D1 R2 & mini, 160 MHz, 921600, 4M (3M SPIFFS)"

/home/chris/Arduino/wemos_D1_mini_seeder_controller_AccelStepper_SPIFFS_gif_heartbe/wemos_D1_mini_seeder_controller_AccelStepper_SPIFFS_gif_heartbe.ino: In function 'void sendSettings()':
wemos_D1_mini_seeder_controller_AccelStepper_SPIFFS_gif_heartbe:405: error: no matching function for call to 'WebSocketsServer::broadcastBIN(uint32_t [2], unsigned int)'
webSocket.broadcastBIN(payload, sizeof(payload));
^
/home/chris/Arduino/wemos_D1_mini_seeder_controller_AccelStepper_SPIFFS_gif_heartbe/wemos_D1_mini_seeder_controller_AccelStepper_SPIFFS_gif_heartbe.ino:405:50: note: candidates are:
In file included from /home/chris/Arduino/wemos_D1_mini_seeder_controller_AccelStepper_SPIFFS_gif_heartbe/wemos_D1_mini_seeder_controller_AccelStepper_SPIFFS_gif_heartbe.ino:7:0:
/home/chris/Arduino/libraries/WebSockets/src/WebSocketsServer.h:80:14: note: bool WebSocketsServer::broadcastBIN(uint8_t, size_t, bool)
bool broadcastBIN(uint8_t
payload, size_t length, bool headerToPayload = false);

          ^

/home/chris/Arduino/libraries/WebSockets/src/WebSocketsServer.h:80:14: note: no known conversion for argument 1 from 'uint32_t [2] {aka unsigned int [2]}' to 'uint8_t {aka unsigned char}'
/home/chris/Arduino/libraries/WebSockets/src/WebSocketsServer.h:81:14: note: bool WebSocketsServer::broadcastBIN(const uint8_t, size_t)
bool broadcastBIN(const uint8_t
payload, size_t length);

          ^

/home/chris/Arduino/libraries/WebSockets/src/WebSocketsServer.h:81:14: note: no known conversion for argument 1 from 'uint32_t [2] {aka unsigned int [2]}' to 'const uint8_t {aka const unsigned char}'
exit status 1
no matching function for call to 'WebSocketsServer::broadcastBIN(uint32_t [2], unsigned int)'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Chris Dalby
@moose4621
Jun 13 2018 20:59
I went down that path because I was not getting the expected array in the console.
Ash
@ashthespy
Jun 13 2018 21:04
@moose4621 with the uint8_t array - what is the Arduino value, and what is the raw buffer you get via the browser console?
Chris Dalby
@moose4621
Jun 13 2018 21:07
The raw value can be up to 300.
var code="
ArrayBuffer(2) {}
[[Int8Array]]
:
Int8Array(2)
0
:
20
1
:
50
buffer
:
(...)
byteLength
:
(...)
byteOffset
:
(...)
length
:
(...)
Symbol(Symbol.toStringTag)
:
(...)
proto
:
TypedArray
BYTES_PER_ELEMENT
:
1
buffer
:
(...)
byteLength
:
(...)
byteOffset
:
(...)
constructor
:
ƒ Int8Array()
BYTES_PER_ELEMENT
:
1
arguments
:
(...)
caller
:
(...)
length
:
3
name
:
"Int8Array"
prototype
:
TypedArray
BYTES_PER_ELEMENT
:
1
buffer
:
(...)
byteLength
:
(...)
byteOffset
:
(...)
constructor
:
ƒ Int8Array()
BYTES_PER_ELEMENT
:
1
arguments
:
(...)
caller
:
(...)
length
:
3
name
:
"Int8Array"
prototype
:
TypedArray
BYTES_PER_ELEMENT
:
1
buffer
:
(...)
byteLength
:
(...)
byteOffset
:
(...)
constructor
:
ƒ Int8Array()
BYTES_PER_ELEMENT
:
1
arguments
:
(...)
caller
:
(...)
length
:
3
name
:
"Int8Array"
prototype
:
TypedArray
BYTES_PER_ELEMENT
:
1
buffer
:
(...)
byteLength
:
(...)
byteOffset
:
(...)
constructor
:
ƒ Int8Array()
BYTES_PER_ELEMENT
:
1
arguments
:
(...)
caller
:
(...)
length
:
3
name
:
"Int8Array"
prototype
:
TypedArray {constructor: ƒ, BYTES_PER_ELEMENT: 1}
Symbol(Symbol.species)
:
(...)
proto
:
ƒ TypedArray()
[[Scopes]]
:
Scopes[0]
length
:
(...)
Symbol(Symbol.toStringTag)
:
(...)
proto
:
Object
Symbol(Symbol.species)
:
(...)
proto
:
ƒ TypedArray()
[[Scopes]]
:
Scopes[0]
length
:
(...)
Symbol(Symbol.toStringTag)
:
(...)
proto
:
Object
Symbol(Symbol.species)
:
(...)
proto
:
ƒ TypedArray()
[[Scopes]]
:
Scopes[0]
length
:
(...)
Symbol(Symbol.toStringTag)
:
(...)
proto
:
Object
Symbol(Symbol.species)
:
(...)
proto
:
ƒ TypedArray()
[[Scopes]]
:
Scopes[0]
length
:
(...)
Symbol(Symbol.toStringTag)
:
(...)
proto
:
Object
[[Int16Array]]
:
Int16Array [12820]
[[Uint8Array]]
:
Uint8Array(2) [20, 50]
byteLength
:
(...)
proto
:
ArrayBuffer
WebSocket.js:25 The specified value "undefined" is not a valid number. The value must match to the following regular expression: -?(\d+|\d+.\d+|.\d+)([eE][-+]?\d+)?
";
Ash
@ashthespy
Jun 13 2018 21:11
Uint8Array(2) [20, 50] - > isn't that the value you passed?
Chris Dalby
@moose4621
Jun 13 2018 21:16
Yes. Feeling stupid now. I thought I was passing something else but you just made me double check and it is correct.
I am still unable to use the array at the client.
Ash
@ashthespy
Jun 13 2018 21:17
What do you try to do now?
It's just a regular array, pop, slice, index do as you please!
Chris Dalby
@moose4621
Jun 13 2018 21:20
connection.onmessage = function (e) {
console.log('Server: ', e.data);
if(event.data instanceof ArrayBuffer ){
var buffer = event.data;
var e=document.getElementById("R").value=buffer[0];
var e=document.getElementById("G").value=buffer[1];
}
Ash
@ashthespy
Jun 13 2018 21:21
check out my snippet from yesterday
you need to put it into a typedarray
Chris Dalby
@moose4621
Jun 13 2018 21:29
Yahoo!
I am forever in your debt Ash. Thank you so much.
Ash
@ashthespy
Jun 13 2018 21:31
Congrats!
No issues! PayItForward :-)
Chris Dalby
@moose4621
Jun 13 2018 21:33
It is so simple now that I can see it working. I have not seen an example like it though.
Ash
@ashthespy
Jun 13 2018 21:34
Yeah - sorry about that - I don't have my usual system here, so couldn't give you a simple example
Btw - it should be super straightforward to change to uint16_t
* Js and  Equivalent C types
╔════════════════════╦════════╦══════════╦════════════════════════════╦════════════════════════════════════════════════════════════════════════════╦══════════════════════╗
║       Type         ║ bytes  ║  C type  ║        Value Range         ║                                Description                                 ║    Web IDL type      ║
╠════════════════════╬════════╬══════════╬════════════════════════════╬════════════════════════════════════════════════════════════════════════════╬══════════════════════╣
║ Int8Array          ║      1 ║ int8_t   ║ -128 to 1278-bit two's complement signed integer                                      ║ byte                 ║
║ Uint8Array         ║      1 ║ uint8_t  ║ 0 to 2558-bit unsigned integer                                                     ║ octet                ║
║ Uint8ClampedArray  ║      1 ║ uint8_t  ║ 0 to 2558-bit unsigned integer (clamped)                                           ║ octet                ║
║ Int16Array         ║      2 ║ int16_t  ║ -32768 to 3276716-bit two's complement signed integer                                     ║ short                ║
║ Uint16Array        ║      2 ║ uint16_t ║ 0 to 6553516-bit unsigned integer                                                    ║ unsigned short       ║
║ Int32Array         ║      4 ║ int32_t  ║ -2147483648 to 214748364732-bit two's complement signed integer                                     ║ long                 ║
║ Uint32Array        ║      4 ║ uint32_t ║ 0 to 429496729532-bit unsigned integer                                                    ║ unsigned long        ║
║ Float32Array       ║      4 ║ float    ║ 1.2x10-38 to 3.4x1038      ║ 32-bit IEEE floating point number ( 7 significant digits e.g. 1.1234567)   ║ unrestricted float   ║
║ Float64Array       ║      8double5.0x10-324 to 1.8x10308    ║ 64-bit IEEE floating point number (16 significant digits e.g. 1.123...15)  ║ unrestricted double  ║
╚════════════════════╩════════╩══════════╩════════════════════════════╩════════════════════════════════════════════════════════════════════════════╩══════════════════════╝
For reference ;-)
Chris Dalby
@moose4621
Jun 13 2018 21:37
? On the server side I am having trouble defining anything other than uint8-t.
It seems to be a limit of the websockets library maybe?
error: no matching function for call to 'WebSocketsServer::broadcastBIN(uint16_t [2], unsigned int)'
webSocket.broadcastBIN(payload, sizeof(payload));
WebSocketsServer.h:80:14: note: bool WebSocketsServer::broadcastBIN(uint8_t, size_t, bool)
bool broadcastBIN(uint8_t
payload, size_t length, bool headerToPayload = false);
note: no known conversion for argument 1 from 'uint16_t [2] {aka short unsigned int [2]}' to 'uint8_t {aka unsigned char}'
Ash
@ashthespy
Jun 13 2018 21:40
It gives you a hint right there - it needs a uint8_t array
So you need to cast it
Chris Dalby
@moose4621
Jun 13 2018 21:42
So, if my max value is 300?
Ash
@ashthespy
Jun 13 2018 21:42
Casting = conversion from one type to another
Chris Dalby
@moose4621
Jun 13 2018 21:43
Oh,
Ash
@ashthespy
Jun 13 2018 21:43
A nice image from the internetz
https://i.stack.imgur.com/gec1a.png
Does it make sense now?
top is a uint8 array , bottom is a uint32 array
Chris Dalby
@moose4621
Jun 13 2018 21:51
No.
Syntax for casting from uint8 to uint16 is where I am stuck.
Chris Dalby
@moose4621
Jun 13 2018 22:00
Off to work again now. Thanks again for your help Ash @ashthespy
Ash
@ashthespy
Jun 13 2018 22:02
(const uint8_t *)&Array doesn't work?
Chris Dalby
@moose4621
Jun 13 2018 22:33
@ashthespy I don't know what you are suggesting.
Ash
@ashthespy
Jun 13 2018 22:57
Hmm..
gimme a second - let me see what I can do.
Ash
@ashthespy
Jun 13 2018 23:05
Disclaimer - this isn't the 'best' way to do it - but it's a way!
Michael Miller
@Makuna
Jun 13 2018 23:23
Understand the Endianness of your processor. An Uint32_t in memory may actually be stored in a different order than you think, the c/c++ compiler will hide this from when using bit operations, but when you cast it to array of 4 bytes, you get to see the out of order bytes.
Ash
@ashthespy
Jun 13 2018 23:25
@Makuna yes - I started typing out a word of caution about that - then gave up with the general disclaimer. :-)
But what is the 'right' way to do this?
rather - is there a convenience function for this?
Michael Miller
@Makuna
Jun 13 2018 23:37
unsure myself on Es8266. Some state that all transmitted binary data should be done in big endian, so its a natural order. Then its upto client/server to always translate using a blob reader that checks local support and exposes methods for serialization/deserialization.
Hone your GoogleFu and do some searching on the terms serialize binary endianness.
Ash
@ashthespy
Jun 13 2018 23:50
@Makuna Given for this usecase (deserialization in client side Js) the Js engine uses the host processors's endianness - so LE most of the times on x86. Would it be possible to force the compiler to use LE on the host microcontroller as well, when packing a struct?