These are chat archives for esp8266/Arduino

26th
Aug 2016
Brendan Smith
@brendanheyu
Aug 26 2016 08:00
@Pablo2048 thanks for that , good idea. See if i can go find an example!
Hi folks, doing the daily commute - thought I'd ask this: using a nodemcu is there anyway to create pwm to use with an IR LED? I'm trying to get my air-conditioners to join the 21st century. I know what i need to do, i just an having difficulty making the mental leap. Is killing my enthusiasm a tiny bit... Any pointers? Thanks!
Ivan Grokhotkov
@igrr
Aug 26 2016 08:15
analogWriteFreq(38000);
// turn on LED:
analogWrite(pin, PWMRANGE / 3);
// turn off LED:
analogWrite(pin, 0);
if sinking current instead of sourcing, replace PWMRANGE/3 and 0 with 2*PWMRANGE/3 and PWMRANGE - 1.
kiralikbeyin
@kiralikbeyin
Aug 26 2016 08:25
i heard nodemcu V2 gone from production all will be V3 is it true?
kiralikbeyin
@kiralikbeyin
Aug 26 2016 09:37
Can anybody help for : Auto read a file and send response when got a "trigger message" from mqtt broker?
Germán Martín
@gmag11
Aug 26 2016 09:43
Hi @igrr , may you confirm this code is right for AsyncWebServer? At least, compiler eats it:
on("/list", HTTP_GET, std::bind(
        [](AsyncFSWebServer* self, AsyncWebServerRequest *request) {
            if (!self->checkAuth(request))
                return request->requestAuthentication();
            self->handleFileList(request);
        }, 
        this, _1));
Ivan Grokhotkov
@igrr
Aug 26 2016 10:01
Maybe poke @me-no-dev, i don't know how checkAuth and handleFileList work. As far as C++ goes, this looks like valid code to me.
Germán Martín
@gmag11
Aug 26 2016 10:07
Sorry @igrr I did not explain. My question is regarding the use of std::bind() to convert [] (AsyncFSWebServer* self, AsyncWebServerRequest *request) to [] (AsyncWebServerRequest *request)
My main doubt is about placeholder _1 is ok. Don't worry about inner code.
Me No Dev
@me-no-dev
Aug 26 2016 10:26
why not capture [this] and not use bind all together?
on("/list", HTTP_GET, [this](AsyncWebServerRequest *request) {
  if (!checkAuth(request))
    return requestAuthentication();
  handleFileList(request);
});
Germán Martín
@gmag11
Aug 26 2016 11:01
Because I did not know it was possible :smile: . I've learnt much C++ here but it I have to learn much more. thank you @me-no-dev :clap:
Me No Dev
@me-no-dev
Aug 26 2016 11:06
@gmag11 here is another capture example:

void runAsyncClient(const char * host, uint16_t port, const char * method, const char * uri){
  AsyncClient * aClient = NULL;
  static int aNum = 0;

  aClient = new AsyncClient();
  if(!aClient)//could not allocate client
    return;

  int cNum = aNum++;
  aClient->onError([cNum](void * arg, AsyncClient * client, int error){
    Serial.printf("Connect Error[%d]: %d\n", cNum, error);
    client = NULL;
    delete client;
  }, NULL);

  aClient->onConnect([host, method, uri, cNum](void * arg, AsyncClient * client){
    Serial.printf("Connected: %d\n", cNum);
    client->onError(NULL, NULL);

    client->onDisconnect([cNum](void * arg, AsyncClient * c){
      Serial.printf("Disconnected: %d\n", cNum);
      delete c;
    }, NULL);

    client->onData([cNum](void * arg, AsyncClient * c, void * data, size_t len){
      Serial.printf("\r\nData[%d]: %d\n", cNum, len);
      Serial.write((uint8_t*)data, len);
    }, NULL);

    //send the request
    char m[256];
    sprintf(m, "%s %s HTTP/1.0\r\nHost: %s\r\n\r\n", method, uri, host);
    int wrote = client->write(m, strlen(m));
    Serial.printf("Sent[%d]: %d\n", cNum, wrote);
  }, NULL);

  if(!aClient->connect(host, port)){
    Serial.printf("Connect Fail: %d\n", cNum);
    AsyncClient * client = aClient;
    aClient = NULL;
    delete client;
  }
}
Germán Martín
@gmag11
Aug 26 2016 11:07
I understand. Then, a lambda can capture as many variables as you need, right?
That's pure C++ power!
It is much more readable. Do you know if it is more efficent too?
Me No Dev
@me-no-dev
Aug 26 2016 11:09
compared to what?
Germán Martín
@gmag11
Aug 26 2016 11:10
to use std::bind
Me No Dev
@me-no-dev
Aug 26 2016 11:10
no idea...
Germán Martín
@gmag11
Aug 26 2016 11:10
ok, does not matter. Thank you again
Stavros Korokithakis
@skorokithakis
Aug 26 2016 14:58
hey everyone
i got one of these high-power LEDs: http://www.vishay.com/docs/81011/tsal6400.pdf
i soldered a 39 ohm resistor in series, but the LED won't turn on at all with 5V
where did i go wrong?
Martin Ayotte
@martinayotte
Aug 26 2016 15:03
How to you know that it is not turning On, since IR is not visible to human eyes.
Stavros Korokithakis
@skorokithakis
Aug 26 2016 15:04
phone camera
Martin Ayotte
@martinayotte
Aug 26 2016 15:04
is your phone camera is really working with IR ?
Stavros Korokithakis
@skorokithakis
Aug 26 2016 15:04
my other IR LEDs show up fine in it
it's not an IR-only camera, it just doesn't filter IR
Martin Ayotte
@martinayotte
Aug 26 2016 15:05
So, for this tsal6400, did you got good polarity ?
Stavros Korokithakis
@skorokithakis
Aug 26 2016 15:05
i think so, i tried both ways to make sure
Martin Ayotte
@martinayotte
Aug 26 2016 15:05
Maybe defective ?
Stavros Korokithakis
@skorokithakis
Aug 26 2016 15:05
hm, maybe
i'm not sure if i got the resistor value right
the calculator said 39 ohms at 5v
that seems to be about ok
Martin Ayotte
@martinayotte
Aug 26 2016 15:06
Probably
Stavros Korokithakis
@skorokithakis
Aug 26 2016 15:06
hmm
Martin Ayotte
@martinayotte
Aug 26 2016 15:07
Do you some spares ?
Stavros Korokithakis
@skorokithakis
Aug 26 2016 15:07
yes, but i only have SMD resistors, so i cut one of the legs and soldered an SMD resistor inbetween
i will try another one though, thanks martin
i connected it to my USB and touched it to the 5V without the resistor, i think that tripped a fuse because the USB won't supply power any more
Stavros Korokithakis
@skorokithakis
Aug 26 2016 15:10
i know, that's what i mean too, i have spares but they're hard to solder
but i will try another one
i got 100 of the ones you linked, but the Vishay ones are high-power
so they were more expensive, 5 for $3 i think
Martin Ayotte
@martinayotte
Aug 26 2016 15:11
Ah ! Ok !
Stavros Korokithakis
@skorokithakis
Aug 26 2016 15:11
these resettable fuses seem pretty cool, better than a diode
a diode will blow, whereas a resettable fuse can start working again
Martin Ayotte
@martinayotte
Aug 26 2016 15:22
which fuses ?
Stavros Korokithakis
@skorokithakis
Aug 26 2016 15:26
pptc
Martin Ayotte
@martinayotte
Aug 26 2016 15:30
Ah ! you mean in general, Yes !
Stavros Korokithakis
@skorokithakis
Aug 26 2016 15:30
yep!
Stavros Korokithakis
@skorokithakis
Aug 26 2016 15:45
is there some machine i can buy that can generate voltage and that will have protection against me being an idiot?
an adjustable power supply, i guess
Stavros Korokithakis
@skorokithakis
Aug 26 2016 16:34
Mehrdad K
@mkeyno
Aug 26 2016 16:48
@martinayotte if had time may I have your opinion about direct hardware print instead of normal serial print , what benefit we can get from following code?
DEBUG_TCP(...) while(((U0S >> USTXC) & 0x7F) != 0x00); os_printf( __VA_ARGS__ ); while(((U0S >> USTXC) & 0x7F) != 0x00)
Martin Ayotte
@martinayotte
Aug 26 2016 17:16
@mkeyno , I don't see what kind of benefit you can get ...
Mehrdad K
@mkeyno
Aug 26 2016 17:50
I saw this code using instead of normal serial print but I don't get what reason for that
kiralikbeyin
@kiralikbeyin
Aug 26 2016 18:52
how can i make wifi reconnect longer than 1 second?
Me No Dev
@me-no-dev
Aug 26 2016 19:12
@mkeyno you see that code probably because Serial used to work a bit differently a little back and the way it worked was leading to excptions and issus if used from system callbacks.
Currently Serial worrks much the same way as in the code above
Mehrdad K
@mkeyno
Aug 26 2016 20:10
@me-no-dev so this is only due to Async conditions to prevent sketch form exceptions , although you already fix the problem so it wont cause any problem to use normal serial print in the call back functions , am I right ?
Me No Dev
@me-no-dev
Aug 26 2016 20:21
yes
you can use the normal Serial.* to print from within async/timer/pin callbacks
Mehrdad K
@mkeyno
Aug 26 2016 20:25
Thanks buddy, I saw couple of repo use such way , this fix is due to your repo enhancement or due to update in Ivan repo