These are chat archives for esp8266/Arduino

23rd
May 2015
Russ Mathis
@RussMathis
May 23 2015 16:40
Thanks guys didn't know this was available.
Russ Mathis
@RussMathis
May 23 2015 16:47
@ficeto got the client connect to work thanks!
Have to head home wife complaining ceiling is leaking LOL
Ivan Grokhotkov
@igrr
May 23 2015 16:48
:)
chad cormier roussel
@chadouming
May 23 2015 16:48
hey, anyone wan't to help me porting the arduino-mysql connector library ? So far it's working-ish. I modified to use our includes and our implementation of hash library. The main problem now is that it take an awful lot of time to connect. Also, once it's done publishing it triggers a WDT. Here is the GitHub repo : https://github.com/chadouming/mysql-connector
Ivan Grokhotkov
@igrr
May 23 2015 16:50
did you try using setNoDelay?
it can reduce latency of your TCP connection
will take a look at the code bit later
chad cormier roussel
@chadouming
May 23 2015 16:59
Well, by an awful lot of time, I mean it take 40 try with one second delay.
also, just tried to add the setNoDelay and it doesn't to make any difference
Michael Miller
@Makuna
May 23 2015 17:11
is anyone looking at providing a servo library? If not, I will take a look.
ficeto
@ficeto
May 23 2015 17:11
i have one
it's in C though still
and since the ESP has one timer
you can not have PWM and Servo at the same time
Michael Miller
@Makuna
May 23 2015 17:12
One? I see three in the docs?
Ivan Grokhotkov
@igrr
May 23 2015 17:12
I was at least two
s/was/saw
ficeto
@ficeto
May 23 2015 17:12
not that type of timer
Michael Miller
@Makuna
May 23 2015 17:12
Actually four, but timer 0 is the built in CCOUNT.
ficeto
@ficeto
May 23 2015 17:12
only one does the job
i think there are actually 8 timers
just not documented
Michael Miller
@Makuna
May 23 2015 17:13
Let me rephrase then, a software timer.
Ivan Grokhotkov
@igrr
May 23 2015 17:13
FRC1 and FRC2 as they are called in Espressif headers
Michael Miller
@Makuna
May 23 2015 17:13
sorry, software Servo library
ficeto
@ficeto
May 23 2015 17:13
let me grab the coe
#define RC_OUTNUM 4
static uint16_t rc_outputs[4] = {1500,1500,1500,1500};
static uint8_t rc_out_pins[4] = {13,12,14,16};

void onRcTimer(){
    static uint8_t rc_current_chan = 0;
    static uint16_t rc_loop_time = 0;
    if(rc_current_chan != RC_OUTNUM){
        uint16_t period = rc_outputs[rc_current_chan];
        timer1_write(period * 5);
        if(rc_current_chan != 0) digitalWrite(rc_out_pins[rc_current_chan - 1], LOW);
        digitalWrite(rc_out_pins[rc_current_chan], HIGH);
        rc_loop_time += period;
        rc_current_chan++;
    } else {
        timer1_write((10000 - rc_loop_time) * 5);
        digitalWrite(rc_out_pins[3], LOW);
        rc_loop_time = 0;
        rc_current_chan = 0;
    }
}

void rcOutputsInit(){
    int i;
    for(i=0; i<RC_OUTNUM; i++){
        pinMode(rc_out_pins[i], OUTPUT);
        digitalWrite(rc_out_pins[i], LOW);
    }
    //updates the screen every second
    timer1_disable();
    timer1_attachInterrupt(onRcTimer);
    timer1_enable(TIM_DIV16, TIM_EDGE, TIM_SINGLE);
    timer1_write(5000000);//1 second
}

void rcOutputsWrite(uint8_t chan, uint16_t value){
    if(value < 700) value = 700;
    else if(value > 2200) value = 2200;
    rc_outputs[chan&3] = value;
}
Michael Miller
@Makuna
May 23 2015 17:16
I was going to just port the existing Arduino software Servo code, gives us compatibility. It does similar things to your code but tracks multiple timers.
ficeto
@ficeto
May 23 2015 17:17
you have int vector on other timers?
Michael Miller
@Makuna
May 23 2015 17:19
let me confirm, but last time I looked I thought I saw that all timers had ISR support.
ficeto
@ficeto
May 23 2015 17:19
that is the reason i used one timer... found only that documented
@chadouming i read this function
int Connector::wait_for_client() {
  int num = 0;
  int timeout = 0;
  do {
    num = client.available();
    timeout++;
    if (num < MIN_BYTES_NETWORK and timeout < MAX_TIMEOUT) {
      delay(100);  // adjust for network latency
    }
  } while (num < MIN_BYTES_NETWORK and timeout < MAX_TIMEOUT);
  return num;
}
seems to be in a while loop in the query method
could it be that?
what if you lower the 100ms time?
ficeto
@ficeto
May 23 2015 17:26
what is the result of that:
#if not defined WIFI
is it defined for esp8266?
chad cormier roussel
@chadouming
May 23 2015 17:26
defined on the top of the header file
ficeto
@ficeto
May 23 2015 17:27
sorry, looking through the browser
chad cormier roussel
@chadouming
May 23 2015 17:28
eh, you are trying to help me, no need to be sorry :P
it seems to me like it's having a hard time to connect to the server
but i know my server is ok
ficeto
@ficeto
May 23 2015 17:30
i thougt you said it sends the request bud gets watchdog after
so i guessed the read method after sending the data
and it lead me to the while loops and that wait function
chad cormier roussel
@chadouming
May 23 2015 17:31
well, it fail a lot of time to connect to the server, then eventually connect, send data then watchdog kicks in
ficeto
@ficeto
May 23 2015 17:31
what do you see on the server log?
have you looked at tcpdump?
Michael Miller
@Makuna
May 23 2015 17:31
@ficeto @igrr The chip supports four compare interrupts on it's one timer, the zero is reserved for CCOUNT. The question is then are all of these exposed through the library.
chad cormier roussel
@chadouming
May 23 2015 17:33
so, i'ved changed the "Shit" to connection failure and here is what it look like in the serial
ficeto
@ficeto
May 23 2015 17:39
that no connect means it cant really connect to the server
why would that bethough
chad cormier roussel
@chadouming
May 23 2015 17:39
well, it eventually does
ficeto
@ficeto
May 23 2015 17:40
what you do in time to sleep?
chad cormier roussel
@chadouming
May 23 2015 17:40
while(!my_conn.mysql_connect(host, 3306, user, password))
{
ESP.wdtFeed(); //Feed the dog.
}
ficeto
@ficeto
May 23 2015 17:45
ok just a wild guess
maybe you need to release the client once you are done
before you try another connect attempt
chad cormier roussel
@chadouming
May 23 2015 17:46
there was a client.close and client.flush but i removed them as a test
ficeto
@ficeto
May 23 2015 17:46
clear the object maybe
because the wdt looks like it triggers on mysql_connect after successful connection
did not trigger on the failed ones
Also check if the Client class (not the wifi client) keeps track of handles
because you keep the client in memory, thus not releasing/disconnecting
which is what you need to keep open connection
but in your example you try to connect again, so you should release for sure first
chad cormier roussel
@chadouming
May 23 2015 17:50
the client is actually a WifiClient
ficeto
@ficeto
May 23 2015 17:50
under WiFiClient is a Client
is it not?
ClientContext

        void ref() {
            ++_refcnt;
            DEBUGV(":ref %d\r\n", _refcnt);
        }

        void unref() {
            DEBUGV(":ur %d\r\n", _refcnt);
            if(--_refcnt == 0) {
                flush();
                close();
                if(_discard_cb) _discard_cb(_discard_cb_arg, this);
                delete this;
            }
        }
chad cormier roussel
@chadouming
May 23 2015 17:51
right, just saw it
ficeto
@ficeto
May 23 2015 17:52
this is how the web surver functions
you get client, do the thing and then do not care
but the client is local to the user
yours is in the class
maybe delete client; will do
then init an empty one
chad cormier roussel
@chadouming
May 23 2015 17:57
hmm, now that i come to think about it, the watchdog is from the query
that's one sure thing
since it never reach the disconnection message
ficeto
@ficeto
May 23 2015 17:58
can you paste that portion of the sketch?
i looked at the DHT one
is that it?
chad cormier roussel
@chadouming
May 23 2015 17:59

/**

  • cmd_query - Execute a SQL statement
    *
  • This method executes the query specified as a character array that is
  • located in data memory. It copies the query to the local buffer then
  • calls the run_query() method to execute the query.
    *
  • If a result set is available after the query executes, the field
  • packets and rows can be read separately using the get_field() and
  • get_row() methods.
    *
  • query[in] SQL statement (using normal memory access)
    *
  • Returns boolean - True = a result set is available for reading
    /
    boolean Connector::cmd_query(const char
    query)
    {
    int query_len = (int)strlen(query);

    if (buffer != NULL)
    free(buffer);

    buffer = (byte *)malloc(query_len+5);

    // Write query to packet
    memcpy(&buffer[5], query, query_len);

    // Send the query
    return run_query(query_len);
    }

ficeto
@ficeto
May 23 2015 18:00
INSERT INTO tempLogging.logs VALUES (NULL, censored, 18.90, 3191, 18.20, NULL)
Yay!
Time to sleep : 300
does that not mean that it sent the query?
or does it mean that it sent it to the outgoing buffer?
where is the "Yay!"
chad cormier roussel
@chadouming
May 23 2015 18:02
in my .ino
ficeto
@ficeto
May 23 2015 18:02
:D
char buf[128];
      sprintf(buf, "INSERT INTO test.temp VALUES (NULL, %hi.%01hi, %i.%01i)",
                   myDHT22.getTemperatureCInt()/10,
                   abs(myDHT22.getTemperatureCInt()%10),
                   myDHT22.getHumidityInt()/10,
                   myDHT22.getHumidityInt()%10);
      my_conn.cmd_query(buf);
      Serial.println("Yay here?");
chad cormier roussel
@chadouming
May 23 2015 18:03
there is a disconnect method, but it seems like it's never run
yeah, pretty much
ficeto
@ficeto
May 23 2015 18:04
you have debug on the serial?
Michael Miller
@Makuna
May 23 2015 18:05
@ficeto @igrr FYI: FRC1 & FRC2 are peripheral features added by esprif for the esp8266, FRC2 looks like it is reserved for the RTC features, and FRC1 is general purpose. The lower level CCOMPARE might be available, I will peek into their values to see if they are enabled.
chad cormier roussel
@chadouming
May 23 2015 18:06
yepo
yep*
ficeto
@ficeto
May 23 2015 18:06
@Makuna look in the esp8266_core_timer1.c file in the core
it's using FRC1
have only that
has one alarm
I can swear I saw 3 more such timers in the register dump, but since I have no clue how to catch the interrupts...
did not bother
@chadouming so if you get the Yey that means the query went through
then what do you do
chad cormier roussel
@chadouming
May 23 2015 18:08
ESP.wdtFeed(); //Feed the dog.
ESP.deepSleep((secondToSleep * 1000000), WAKE_NO_RFCAL);
more exactly,

temperature = dht.readTemperature();
humidity = dht.readHumidity();
delay(200);

//unsigned long unixTime = ntpUnixTime(udp);
//unsigned long nextTime = (floor(unixTime/interval)*interval)+interval;
unsigned int secondToSleep = 300;//(nextTime - unixTime) + 30;

char buff[100];
sprintf(buff, qry, key, f2s(temperature, 2), vcc, f2s(humidity, 2));

my_conn.cmd_query(buff);
delay(1000);

if defined(DEBUG)

Serial.println(buff);

endif

if defined(DEBUG)

Serial.println(F("Yay!"));
Serial.println("Time to sleep : " + (String)secondToSleep);

endif

ESP.wdtFeed(); //Feed the dog.
ESP.deepSleep((secondToSleep * 1000000), WAKE_NO_RFCAL);
delay(2000);

Michael Miller
@Makuna
May 23 2015 18:09
@ficeto It references ETD_FRC1_INT*, if you look in eagle_soc.h, you can see the reference to FRC2 and how it gets tied to the RTC.
ficeto
@ficeto
May 23 2015 18:09
but FRC2 is used
so did not want to mess that
and i think FRC2 is only timer
will look again... might have an outdated version
Michael Miller
@Makuna
May 23 2015 18:11
yup. the CCOMPARE are chip features not peripherals like FRC1 & FRC2, if they aren't being used by something within the ROM, then that is three I could use.
ficeto
@ficeto
May 23 2015 18:11
when looking at the register dump (in docs in the repo) you can see the two types of timers
one type has the extra alarm register
Michael Miller
@Makuna
May 23 2015 18:11
(love PSOC terminology)
ficeto
@ficeto
May 23 2015 18:11
COMPARE is you will
@Makuna if you know how :) show us! Would love to learn something new
@chadouming you got through all that
you think the sleep woke up?
chad cormier roussel
@chadouming
May 23 2015 18:13
it's 5 minutes of sleep, i'd doubt so
Michael Miller
@Makuna
May 23 2015 18:13
@ficeto CCOMPARE is a chip register, (240-242), each has a interrupt, but not sure they aren't being used yet. I will let you know.
ficeto
@ficeto
May 23 2015 18:14
so it did not go at all
try to unref the client once done
chad cormier roussel
@chadouming
May 23 2015 18:14
what i just did
ficeto
@ficeto
May 23 2015 18:14
you can put it in the destruct method of the class
chad cormier roussel
@chadouming
May 23 2015 18:14
well, ran the disconnect method
ficeto
@ficeto
May 23 2015 18:14
no.. it's not the same
chad cormier roussel
@chadouming
May 23 2015 18:14
so far, watch dog is not triggered
ficeto
@ficeto
May 23 2015 18:14
that will not unref()
i think...
chad cormier roussel
@chadouming
May 23 2015 18:15
well, disconnect method call client.stop, which call to unref
ficeto
@ficeto
May 23 2015 18:15
@Makuna chip registers you mean those with 0x3ff....
chad cormier roussel
@chadouming
May 23 2015 18:15
i'll tell you in 5 minutes if that fixed the watch dog xD
ficeto
@ficeto
May 23 2015 18:16
@chadouming fingers crossed :D
Michael Miller
@Makuna
May 23 2015 18:17
@ficeto No prefix at all, anything with the prefix (0x??000000) are peripherals.
@ficeto Peripherals just means specific features "programmed" into the PSOC rather than inherently/commonly supported.
ficeto
@ficeto
May 23 2015 18:18
ok... i think i get it
like pseudo registers of the sort
i wanted to make such thing to control the I2C speed
so user libs that have TWI = x; can work
chad cormier roussel
@chadouming
May 23 2015 18:20
ok, so calling disconnect before going into deep sleep seems to have fixed the watch dog problem
ficeto
@ficeto
May 23 2015 18:20
ok so how much info there is on such registers
chad cormier roussel
@chadouming
May 23 2015 18:21
only problem now is that is take roughly ~30 attempt to connect to the server xD
ficeto
@ficeto
May 23 2015 18:21
that is funky...
i imagine it's not a busy server?
Michael Miller
@Makuna
May 23 2015 18:21
@ficeto The CCOMPARE are in the Xtensa instruction set documentation.
chad cormier roussel
@chadouming
May 23 2015 18:22
nope, my own server i got just for that
i also ping @about 13ms, so i'd doubt it's a timeout issue
ficeto
@ficeto
May 23 2015 18:22
no... it should not be
try tcp dump to see who rejects the connection
maybe will have a clue in the packet that succeeded
@Makuna not familiar with it, but it's great to see someone is
I imagine there is lots more to unlock from the ESP
having one timer with interrupt definetelly sucks
chad cormier roussel
@chadouming
May 23 2015 18:25
hmm, packet just flows on tcpdump
all coming from the esp, so i guess there i a problem somewhere xD
ficeto
@ficeto
May 23 2015 18:26
flags are important
the letters in square brackets
chad cormier roussel
@chadouming
May 23 2015 18:26
most of them are [P] and [.]
ficeto
@ficeto
May 23 2015 18:26
there will not be much else as they are connection init SYN requests
P is push, means somthing is going through
I think [.] is ACK but can not tell like that :D
pastebin a part of it
chad cormier roussel
@chadouming
May 23 2015 18:28
have to go to work, i'll continue to work on this later
ficeto
@ficeto
May 23 2015 18:29
this is your ssh that we see
you will need to filter by port best
chad cormier roussel
@chadouming
May 23 2015 18:29
ah, that does make sense
much sense actually
ficeto
@ficeto
May 23 2015 18:30
I hope it will help
chad cormier roussel
@chadouming
May 23 2015 18:35
with filter
ficeto
@ficeto
May 23 2015 18:37
ok first you got reconnect
then you got connect
in a mean time the server did not even hear your SYN packets for opening a connection
then communication worked
should packets be that many?
1 byte a packet?
ficeto
@ficeto
May 23 2015 18:42
for (int c = 0; c < query_len+5; c++)
    client.write(buffer[c]);
//to become
client.write(buffer, query_len+5);
then see what is required to disconnect since you will be rebooting
maybe the server did not catch your disconnect?
the reconnect you got was from earlier attempt
will not help with the mysql
connect though
since you are at home probably and your ESP is there
get a MAMP server (if you are on windows) and try localy
the VPS might be the reason
chad cormier roussel
@chadouming
May 23 2015 18:51
I'll test that as soon as i'll be back home
ficeto
@ficeto
May 23 2015 18:51
I can't wait you get this working
it's amazing
chad cormier roussel
@chadouming
May 23 2015 18:53
Well, it will allow me to send data securely instead of using my php api
ficeto
@ficeto
May 23 2015 18:54
it allows so many things
chad cormier roussel
@chadouming
May 23 2015 18:54
I wonder how long my sensors will last on battery vs a simple get request tho
ficeto
@ficeto
May 23 2015 18:54
with the WebSocket that @Links2004 is working on.... amazing
will not need get requests
:)
i imagine if the server responds well, the connection cost would not be much more than opening a client and posting somewhere
after all that is what you are doing
packet is not that large... most request headers are quite more
so should be nice... did not calculate the sha cost
Michael Miller
@Makuna
May 23 2015 19:06
@ficeto @igrr Did some quick investigation with code, the CCOMPARE1 & CCOMPARE2 are not available (invalid registers) but CCOMPARE0 is available and doesn't seem to be used. Digging more...
Russ Mathis
@RussMathis
May 23 2015 22:38
Do I have to use WiFi.mode(WIFI_AP); or can i Just use
WiFi.SoftAPConfig with WiFi.softAp();
Ivan Grokhotkov
@igrr
May 23 2015 22:40
You need to set WiFi.mode(WIFI_AP) before doing WiFi.softAP()
Russ Mathis
@RussMathis
May 23 2015 22:51
k, thx
When creating examples for the wiki should we just create a single file for each or just keep appending to the current single wiki page.
Ivan Grokhotkov
@igrr
May 23 2015 23:00
Maybe a page for a set of related examples...
or a new page for each if they get lengthy
Russ Mathis
@RussMathis
May 23 2015 23:01
k