-->
Page 1 of 2

A little example with Neopixel leds

PostPosted: Sat Mar 05, 2016 10:20 am
by cicciocb
]Hi all,
this is not really a project but more as an example of what can be done with ESP Basic.
This example is a simply web page that permit to control the color of a WS2812B stripline.
Nothing complicated, I know, but the example is more for how is done.
In fact is a combination of css, javascript and basic permitting to control the mix of colors.

This is the basic code :
[start]
cls
css "display.css"
wprint |<title>NeoPixel Text</title>|
wprint |<form>|
wprint |<head>|
wprint |<script type="text/javascript" src="/file?file=neo.js">"></script>|
wprint |</head>|
wprint |<script> initme(); WritePage(); </script>|
wprint |</form>|
msgbranch [messaggio]
wait
[messaggio]
msgget "color" mess
if mess == "@EX_IT@" then end
'serialprintln mess
let red = mid(mess,8,3)
let green = mid(mess,12,3)
let blue = mid(mess,16,3)
neostripcolor(0,29,red,green,blue)
wait

There is a javascript code (attached) and a css file (attached too).
As you can see the basic code is very "basic", only few lines.
The web page is created into the javascript and styled with the .css .
In fact all the communication is based on AJAX.
Don't be scared, nothing complicated.
What happens is that, each time a slider is moved or the button "Set Color" is pressed, the javascript make a direct "ajax" request to the basic sending the color; this is achieved with the command "msgbranch [messaggio]" that "jumps" to the label [messaggio].
After that, you can recover the value sent by the javascript with the command 'msgget "color" mess'.

Sorry, I forgot to say that this page is optimized for the I-phone 6 and Google Chrome.

Regards,
Cicciocb

Re: A little example with Neopixel leds

PostPosted: Sat Mar 05, 2016 6:00 pm
by Mmiscool
Cool.

It is always interesting to see how to do things using java script in the browser. Interfacing with the msg branch using java script is an effective way to get some really complex behavior in the browser to do some thing in the real world using the basic code on the esp.

Thanks for sharing, :-D

Re: A little example with Neopixel leds

PostPosted: Sat Mar 05, 2016 7:29 pm
by forlotto
msgget is the only secure way to interface real world otherwise for just basic stuff there is no need to do any message branch to be honest just use the goto link and it will function the same as msg branch.

THIS IS THE BIGGEST VULNERABILITY WITH ESPBASIC! for security reasons and saftey reasons there should be random data inserted into this as well to prevent someone from turning something on remotely without your permission and causing harm to people or damage to property. I think everyone should be warned about this because the standardized web pages use /input?goto2=OFF for instance common names like this I would guess fairly easily and start turning your lights on at 3AM in the morning or turning on your coffee pot or whatever you folks plan to do with these things. You see it is not the most secure way of doing things without the interpreter itself adding a little randomness to what you are going to it could leave you vulnerable especially folks who use these as garage door openers.

KEEP THIS IN MIND!

One way to fix it is to personally randomize your routine that your button goes to so instead of calling your routine for your off button OFF or whatever is close to that the routine you may want to name FckGWRhqq2 this way some would be tinkerer would not come along and try to start randomly controlling devices on your IP as of right now we are a small niche but incorporation of randomness is important for security purposes. Something all should be made aware of!

This is why I don't understand the need for all of these thinger.io pages and so on so forth why would you want a third party handling things? It is super simple to handle them locally, remotely, and dynamically with JAVA based web page this was a great example of that.

Now real time may prove somewhat impossible but you can get close enough to it.

What I would like to see myself is example of a weekly timer web page that can store like 10 timers a day for people who want to set something to come on like a relay for lighting or a thermostat etc it would be nice to have a java frame work I have an interesting dynamic java framework for buttons like this you would just have to edit the pages etc...

I would bet that somehow someone could build an application that will just build a java page for people based off of their code and buttons to convert the code to java however one would have to input their IP which could likely be stored as a cookie or something possibly tied to a login or login information tied to an updateable IP a lot of cool stuff would and could be done then. This would be one of those if you build it they will come type moments for espbasic.

Re: A little example with Neopixel leds

PostPosted: Sat Mar 05, 2016 9:26 pm
by Mmiscool
For security purposes I would highly suggest using a web server and poking only 1 hole in your firewall with access to that server. Have it do all of the authentication and have it talk to all of the devices on the internal network.

You may also optionally ad a password box to your programs. Make sure that the variable for the password box is cleared before hitting the wait command.

most secure.png