i hope you can help me with a problem, im not really deep into python or javascript and need some help with the following Project, i tried out the offered solution in this thread but I'm stuck right now...
Project
I'm hosting a Webinterface on my Raspberry Pi, in this Webinterface i included a colorpicker with Javascript. Now i want to send send the RGB-values to a python script. In this Script i want to request these values and use them for controlling a RGB-LED Strip (the controlling part works).
Problem
My Problem is the communication between Javascript and Python, i don't get Python to request the values. Im using Jquery referring to the description i mentioned at the beginning.
Working until now
- i get the RGB Values seperated out of the colorpicker
- I can see in the Chrome-Browser, that my Webpage is sending data to my python script
Code:
Webinterface
<script type="text/javascript">
$('#picker').colpick({
flat:true,
layout:'hex',
submit:0,
colorScheme: 'dark',
onChange:function(hsb,hex,rgb,el,bySetColor){
var rdata= {'rcolor' :rgb.r};
var gdata= {'gcolor' :rgb.g};
var bdata= {'bcolor' :rgb.b};
$.post("/led.py",rdata);
$.post("/led.py",gdata);
$.post("/led.py",bdata);
}
});
Pythonscript
def rgb_data(request):
if request.method == 'POST':
if 'rcolor' in request.POST:
rcolor = request.POST['rcolor']
setLights(RED_PIN, rcolor)
if 'gcolor' in request.POST:
gcolor = request.POST['gcolor']
setLights(GREEN_PIN, gcolor)
if 'gcolor' in request.POST:
brcolor = request.POST['bcolor']
setLights(BLUE_PIN, bcolor)
print(request.POST)?