News

moodlite - Coming soon


Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - spigot

Pages: 1 2 3 ... 8
1
moodlite Software / Re: invalid use of member function
« on: September 28, 2019, 12:58:10 PM »
Hi.

You can completely remove this part:

Code: [Select]
class ByteString : public String {
public:
ByteString(void *data, size_t len) :
String() {
copy(data, len);
}

ByteString() :
String() {
}

String& copy(const void *data, unsigned int length) {
if (!reserve(length)) {
invalidate();
return (*this);
}
len = length;
memcpy(buffer, data, length);
buffer[length] = 0;
return (*this);
}
};

// Asynchronous TCP Client to retrieve data/time
struct AsyncHTTPClient {
AsyncClient *aClient = NULL;

bool         initialized = false;
String       protocol;
String       base64Authorization;
String       host;
int          port;
String       uri;
String       request;

ByteString   response;
int          statusCode;
void(*onSuccess)();
void(*onFail)(String);

void initialize(String url) {
// check for : (http: or https:
int index = url.indexOf(':');

if (index < 0) {
initialized = false; // This is not a URLs
}

protocol = url.substring(0, index);
DEBUGLN(protocol);
url.remove(0, (index + 3)); // remove http:// or https://

index = url.indexOf('/');
String hostPart = url.substring(0, index);
DEBUGLN(hostPart);
url.remove(0, index); // remove hostPart part

// get Authorization
index = hostPart.indexOf('@');

if (index >= 0) {
// auth info
String auth = hostPart.substring(0, index);
hostPart.remove(0, index + 1);                // remove auth part including @
base64Authorization = base64::encode(auth);
}

// get port
port = 80; //Default
index = hostPart.indexOf(':');
if (index >= 0) {
host = hostPart.substring(0, index); // hostname
host.remove(0, (index + 1));         // remove hostname + :
DEBUGLN(host);
port = host.toInt();                 // get port
DEBUGLN(port);
}
else {
host = hostPart;
DEBUGLN(host);
}
uri = url;
if (protocol != "http") {
initialized = false;
}

DEBUGLN(initialized);
request = "GET " + uri + " HTTP/1.1\r\nHost: " + host + "\r\n\r\n";

DEBUGLN(request);
initialized = true;
}

int getStatusCode() {
return (statusCode);
}

String getBody() {
if (statusCode == 200) {
int bodyStart = response.indexOf("\r\n\r\n") + 4;
return (response.substring(bodyStart));
}
else {
return ("");
}
}

static void clientError(void *arg, AsyncClient *client, int error) {
DEBUGLN("Connect Error");
AsyncHTTPClient *self = (AsyncHTTPClient *)arg;
self->onFail("Connection error");
self->aClient = NULL;
delete client;
}

static void clientDisconnect(void *arg, AsyncClient *client) {
DEBUGLN("Disconnected");
AsyncHTTPClient *self = (AsyncHTTPClient *)arg;
self->aClient = NULL;
delete client;
}

static void clientData(void *arg, AsyncClient *client, void *data, size_t len) {
DEBUGLN("Got response");

AsyncHTTPClient *self = (AsyncHTTPClient *)arg;
self->response = ByteString(data, len);
String status = self->response.substring(9, 12);
self->statusCode = atoi(status.c_str());
DEBUGLN(status.c_str());

if (self->statusCode == 200) {
self->onSuccess();
}
else {
self->onFail("Failed with code " + status);
}
}

static void clientConnect(void *arg, AsyncClient *client) {
DEBUGLN("Connected");

AsyncHTTPClient *self = (AsyncHTTPClient *)arg;

self->response.copy("", 0);
self->statusCode = -1;

// Clear oneError handler
self->aClient->onError(NULL, NULL);

// Set disconnect handler
client->onDisconnect(clientDisconnect, self);

client->onData(clientData, self);

//send the request
client->write(self->request.c_str());
}

void makeRequest(void(*success)(), void(*fail)(String msg)) {
onFail = fail;

if (!initialized) {
fail("Not initialized");
return;
}

if (aClient) {           //client already exists
fail("Call taking forever");
return;
}

aClient = new AsyncClient();

if (!aClient) {           //could not allocate client
fail("Out of memory");
return;
}

onSuccess = success;

aClient->onError(clientError, this);

aClient->onConnect(clientConnect, this);

if (!aClient->connect(host.c_str(), port)) {
DEBUGLN("Connect Fail");
fail("Connection failed");
AsyncClient *client = aClient;
aClient = NULL;
delete client;
}
}
};

AsyncHTTPClient httpClient;


It's no longer needed

2
moodlite Software / moodlite software [3.0] Release
« on: April 28, 2019, 05:46:19 PM »

3
moonlite Builds / Re: Spigot's Build Log
« on: April 07, 2019, 07:36:46 AM »
First check +5V, GND on both sides (USB and Arduino).

Maybe this helps:

4
moodlite Software / Re: MQTT Error Code
« on: April 07, 2019, 07:33:34 AM »

5
moodlite Software / Re: Cant build moodlite.ino
« on: April 07, 2019, 07:32:59 AM »

6
moonlite Builds / Re: Spigot's Build Log
« on: March 31, 2019, 06:37:27 PM »
Sure. But the soldering is terrible. ::) I was planning to fix it.   >:(



7
moonlite Builds / Re: Spigot's Build Log
« on: March 24, 2019, 03:39:35 PM »
Have you split your cable and use 2 micro usb cables or have you a diffent power supply for each micro usb port?

I'm using only one power supply connected to the micro board. The Wemos D1 and LEDs are powered from this micro board.

The Wemos D1 micro usb is used only for direct connection from my computer.

8
moodlite Design / Re: MQTT Support
« on: March 24, 2019, 03:35:26 PM »
This is my actual HASS code for RGB LED:

Code: [Select]
  - platform: mqtt
    name: rgb_moodlite
    brightness_state_topic: "Moodlite/Brightness/Get"
    brightness_command_topic: "Moodlite/Brightness/Set"
    state_topic: "Moodlite/Backlight/Get"
    command_topic: "Moodlite/Backlight/Set"
    payload_on: "1"
    payload_off: "0"
    rgb_state_topic: "Moodlite/Color/Get"
    rgb_command_topic: "Moodlite/Color/Set"
    optimistic: false
    qos: 0
    retain: false

9
moodlite Software / Re: Turn off the display
« on: February 27, 2019, 07:35:33 AM »
@Klippi

To turn on/off the LEDs during day I'm using HomeAssistnat and PIR sensor.
When I'm not at home, HA turns off the LEDs.
Or when I'm at home the LEDs are turned off and when PIR detect motion it turns on LEDs and after some time PIR turns off the LEDs.

10
moodlite Software / Re: brightness with day cycle
« on: February 27, 2019, 07:30:11 AM »
Hi.

    I already did one project with LDR, but for me it isn't very reliable. It shouldn't be hard to implement. I'll look into it.

11
moodlite Software / Re: Timezone for next release code modification
« on: February 27, 2019, 07:27:40 AM »
Hi.

Showing actual time is already implemented in the new Web interface.
I think the best way to handle time/timezones would be thorough web interface. I'll try to look into it, it won't be a small change.

12
moonlite Builds / Re: Spigot's Build Log
« on: February 08, 2019, 02:52:55 PM »
Hi Gotchar.

   I'm using power supply from Motorola



The 8.1A would by white (all 3 LEDs On) at maximum brightness, but I don't use that way.

I have these parameters:
Brightness: 10-20
Colors: Rainbow
Pattern: Standard

And there's no problem with power.

13
moodlite Electronics / Re: power drop ?
« on: February 01, 2019, 06:50:38 PM »
I found out that I have a I2C level conversion mode.



I'm going to try it this weekend.

14
moodlite Electronics / Re: power drop ?
« on: February 01, 2019, 04:53:19 PM »
And what about capacitor? Do you use one? It should help (For fast switching effects it's useful).

15
moodlite Software / Re: moodlite software [2.0] Release
« on: February 01, 2019, 03:32:37 PM »
I've already mentioned it few times: europe.pool.ntp.org

You can use any NTP server, it has noting to do with the arduino code.

Pages: 1 2 3 ... 8

SMF spam blocked by CleanTalk