These are chat archives for Makuna/NeoPixelBus

16th
Dec 2016
jakeloggins
@jakeloggins
Dec 16 2016 03:01
@Makuna Here's the link to the christmas tree tutorial. Thanks again for your work on this library.
Michael Miller
@Makuna
Dec 16 2016 07:40
@jakeloggins Added it here
@joefly888 A UDP packet is what ever you send. Its just a blob of binary data; but if you send text, you can assume text (C++ text is null terminated)
How are you displaying that?
joefly888
@joefly888
Dec 16 2016 18:02
@Makuna i am receiving over esp and looking at serial port through Arduino IDE and also tried Putty, same thing. Unfortunately not getting any support from lightshowpi.org now, but here is the code snippet from the server that broadcast the data to client rpi with the lightcontroller,
def receive(self):
    """Receive the data sent from the server and decode it

    :return: data
    :rtype tuple: np.array | tuple
    """
    try:
        data, address = self.network_stream.recvfrom(self.network_buffer)
        data = cPickle.loads(data)
    except (IndexError, cPickle.PickleError):
        data = tuple(np.array([0 for _ in range(cm.hardware.gpio_len)]))

    return data

def broadcast(self, *args):
    """Broadcast data over the network

    args will be pickled before being sent

    :param args: (list of lists) to broadcast clients channel data

                    (tuple) pin, brightness pair

    :type args: list | tuple
    """
    if self.networking == "server":
        try:
            data = cPickle.dumps(args)
            self.network_stream.sendto(data, ('<broadcast>', self.port))
        except socket.error, msg:
            if msg[0] != 9:
                log.error(str(msg[0]) + ' ' + msg[1])
                print str(msg[0]) + ' ' + msg[1]
Michael Miller
@Makuna
Dec 16 2016 18:23
@joefly888 Is that Python? Unfamiliar with what ever language that is.
I meant, how are you actually taking the data and printing it to the serial port on the ESP ;-) It just maybe how you are doing it.
joefly888
@joefly888
Dec 16 2016 18:25
@Makuna i am using a script I found online for esp UDP

include <ESP8266WiFi.h>

include <WiFiUdp.h>

WiFiUDP port;

char packetBuffer[255];
unsigned int localPort = 8888;

void setup() {
Serial.begin(250000);
WiFi.begin("S", "");
port.begin(localPort);
}

void loop() {
int packetSize = port.parsePacket();
// Serial.println(packetSize);
if (packetSize) {
int len = port.read(packetBuffer, 255);
if (len > 0) packetBuffer[len-1] = 0;
Serial.println(packetBuffer);
port.beginPacket(port.remoteIP(),port.remotePort());
port.write("Your UDP packet was received OK\r\n");
port.endPacket();
}
// delay(500);
}

Michael Miller
@Makuna
Dec 16 2016 18:29
Ah, its Python; and the clue here is search for cnumpy.core.multiarray and you find information. I am completely unfamiliar with scripts as I always work as close to the hardware as possible.
joefly888
@joefly888
Dec 16 2016 18:32
@Makuna so the receiving code on ESP is ok? I need to delve deeper into what the server is sending?
Michael Miller
@Makuna
Dec 16 2016 18:35
@joefly888 Yeah. What you are seeing in the front seems to be some sort of encoding, where chars outside normal asci are encoded, \x followed by two hex value, the rest is normal ascii.
jakeloggins
@jakeloggins
Dec 16 2016 18:36
@joefly888 so the code here is server > rpi > esp > ??? > light strand ?
joefly888
@joefly888
Dec 16 2016 18:37
@Makuna thank you for your help for you guidance, i will study the server code
@jakeloggins the rpi is running a server lightshowpi.org that dictate how the lights light up, it has ability to broadcast over UDP, so I am caputuring this with ESP with LED attached
jakeloggins
@jakeloggins
Dec 16 2016 18:45
@joefly888 where is the code for communicating to the pi as a client? I'm looking through the bitbucket now
joefly888
@joefly888
Dec 16 2016 18:49
@jakeloggins thanks for your help. I need it. the python code is all in the py folder https://bitbucket.org/tom_slick/lightshowpi-led/src/76b1b0c31973ef496752572168196cef0d46a244/py/?at=lightshowpi-led t
jakeloggins
@jakeloggins
Dec 16 2016 18:50
Is this function what you're trying to recreate on the esp?
def network_client():
    """Network client support

    If in client mode, ignore everything else and just
    read data from the network and blink the lights
    """
that's from synchronized_lights.py
joefly888
@joefly888
Dec 16 2016 18:51
@jakeloggins yes that this the part, sychronized_lights.py is the main script and then it calls networking.py
jakeloggins
@jakeloggins
Dec 16 2016 18:53
@joefly888 have you thought about installing micropython on the esp? I'm not familiar with it so there might be some obvious reason why that won't work.
@joefly888 also, are you trying to fade the lights, or simply turn them off and on?
joefly888
@joefly888
Dec 16 2016 18:54
@jakeloggins micropython seems fun and I will get to it, but right now, it would add a lot of overhead to it so I dont think it is appropriate
jakeloggins
@jakeloggins
Dec 16 2016 18:55
@joefly888 ok, second suggestion. Get a pi zero, connect it to wifi with the esp, run everything as normal.
joefly888
@joefly888
Dec 16 2016 18:55
@jakeloggins see what I have now https://youtu.be/G8mDM0ybrqg it is neopixel cube I made, but it is attached to RPI now, so trying to make it wireless, detached from rpi
@jakeloggins replacing the rpi with a rpi zero really does not solve what i am trying to accomplish
jakeloggins
@jakeloggins
Dec 16 2016 18:57
what are you trying to accomplish? hanging it from the ceiling?
my point is, you have well written network client functionality within that repo. If you can use micropython or a rpi zero to use that code, it would be better than fiddling around with that UDP library
joefly888
@joefly888
Dec 16 2016 19:00
@jakeloggins ideally I would not have to touch the UDP library, once I can understand what it is sending out, I just have to utilize its output for controling leds on ESP
jakeloggins
@jakeloggins
Dec 16 2016 19:13
@joefly888 I think what you are trying to do is fundamentally incompatible with the repo you are using. The UDP data you are getting has been serialized with cPickle. You are then trying to parse it from Arduino/C++. Someone had a similar idea in this thread: https://forum.arduino.cc/index.php?topic=351822.0
From networking.py:
    def broadcast(self, *args):
        """Broadcast data over the network

        args will be pickled before being sent
joefly888
@joefly888
Dec 16 2016 19:18
@jakeloggins thanks for the headsup, Let me get my head around the code, ideally I can just decipher the output on ESp, if not I may tackle writing a new broadcasting code to the ESP, but i am getting ahead of myself...let me get to understand what other have written first. Thanks for your comments
jakeloggins
@jakeloggins
Dec 16 2016 19:19
@joefly888 If I were you, I'd go ask the micropython guys for advice. If it is doable, you can just plug and play.
joefly888
@joefly888
Dec 16 2016 20:14
@Makuna I have just gone back to basics. Got a python code on on network sending 1 & 0 text in .2 second intervals. On esp, I have got it receive the UDP packets and turn on/off Neopixel. But somehow the lights are not blinking in timing.. blinks for 2 times on time, then a off rythm blink, then the cycle repeats. is there something I am doing wrong? esp code here

@Makuna
int packetSize = port.parsePacket();
// Serial.println(packetSize);
if (packetSize) {
int len = port.read(packetBuffer, 255);
if (len > 0) packetBuffer[len-1] = 0;
Serial.println(packetBuffer);

    if (strcmp(packetBuffer, "1") == 0) {
        Serial.println("Turn led ON \n");
        strip.SetPixelColor(0, red);
    } else if (strcmp(packetBuffer, "0") == 0) {
        Serial.println("Turn led OFF \n");
        strip.SetPixelColor(0, black);;
    } else {
        Serial.println("what is this?! \n");
    } 
strip.Show();
//port.beginPacket(port.remoteIP(),port.remotePort());
//port.write("Your UDP packet was received OK\r\n");
//port.endPacket();

}
// delay(500);
}

joefly888
@joefly888
Dec 16 2016 22:22
@Makuna, the delay was caused by the LAN , when I set up the ESp as a AP then the response was really good. A test script to send UDP on off at .03 second intervals (any faster, basically can't see the diff) to esp with neopixel Thanks