Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catfeeder is not coonecting with the wifi router #1

Open
tmmsunny012 opened this issue Jan 9, 2020 · 7 comments
Open

Catfeeder is not coonecting with the wifi router #1

tmmsunny012 opened this issue Jan 9, 2020 · 7 comments

Comments

@tmmsunny012
Copy link

After trying to setup network the serial monitor does not show the SSID and Password. Also, it doesn't connect with my router. Before that happens it starts making the server. blow is the serial log -

191 JSON file size: 193 bytes
{
"ip": [
192,
168,
1,
1
],
"netmask": [
255,
255,
255,
0
],
"gateway": [
192,
168,
1,
2
],
"dns": [
8,
8,
8,
8
],
"dhcp": false,
"ntp": "es.pool.ntp.org",
"NTPperiod": 15,
"timeZone": 10,
"daylight": true,
"deviceName": "CatFeeder"
}Data initialized.
SSID: PASS:
NTP Server: es.pool.ntp.org
bool AsyncFSWebServer::load_config()
Failed to open secret file
void AsyncFSWebServer::configureWifi()
bcn 0
del if1
mode : sta(a0:50:b3:6a:6c:29)
Connecting to
NO DHCP - Use static connection
MAC Addr: A0:50:B3:6A:6C:29
Open http://192.168.1.1/ to manage the CatFeeder
Flash chip size: 4194304
Scketch size: 444880
Free flash space: 1650688
HTTP server started

OTA Ready
END Setup

what should I do in that case? the esp8266 SDK 2.5 doesn't compile now with the new cat slot code. I am currently using 2.6.0 SDK to solve that ..

Another question-
what version of Arduino you are using to compile your code?

@juanmcasillas
Copy link
Owner

Lets see.
The config (config.json) file should look like:

{
"ssid":"WLAN_XXXX",
"pass":"XXXX",
"ip":[192,168,1,1],
"netmask":[255,255,255,0],
"gateway":[192,168,1,2],
"dns":8,8,8,8],
"dhcp":false,"ntp":"es.pool.ntp.org",
"NTPperiod":15,
"timeZone":10,
"daylight":true,
"deviceName":"CatFeeder"
}

Looks like the "ssid" and "pass" fields are not inside the config.json file.
Also, you're using 192.168.1.1 as CatFeeder IP and 192.168.1.2 for the router. Is this right?

Let's see some versions:

I use: ESP8266 by ESP8266 Community version 2.5.0
Arduino IDE: 1.8.10
Can you paste the compilation log, to check the errors?

Thank in advance,

@tmmsunny012
Copy link
Author

tmmsunny012 commented Jan 12, 2020 via email

@juanmcasillas
Copy link
Owner

Hi Juanmcasillas/Catfeeder-Slot thanks for coming back to me. Unfortunately, the problem was not linked with any of this. The problem is coming from SPIFFS. I just figured it by reading some blogs. I was using 2 MB FS with OTA 1019KB.. it was effecting the flash and unable to create a config file. After I changed it to 3MB FS (OTA 512KB), it works perfectly now.

I forget to mention that. You need at least 2 MB FS to get the thing works :-)
Glad to hear that works for you.

Few questions I want to ask - 1. I saw that if the Esp8266 goes off the scheduler time values are gone. Is that normal?

Yes, These boards doesn't include a RTC (Real Time Clock). These tiny (an cheap) devices, backup the state with a battery (usually CR 3022) and they avoid to lose the time when the microcontroller lost the power. These breakout boards are easy to integrate (usually they "speak" I2C). See for more info:

I use NTP sync to keep the time "uptime". So you don't need to worry about losing the time. But if you need more robust time control, get a RTC breakout board and integrate it.

  1. I have designed a feeder that has a screw that takes out food from the reservoir. Instead of making it slot, I did this process. In that case which part of the codes should change? A few
    suggestions might help as I not that advanced coder like you.

CatFeeder-Slot works in this way (pseudocode).

For Each second
     If time == Scheduled Time:
          move_to_next_slot

If you need to configure it for your needs, you have modify some code. See catfeeder.cpp

void CatFeederClass::CheckScheduler(void *arg) {
    // USE self instead of this
    // this function is called each CatFeederClass::SCHEDULE_PERIOD (1 second)
    CatFeederClass *self = reinterpret_cast<CatFeederClass *>(arg);

    int programs = self->getPROGRAMS();
    unsigned long mystamp,prgstamp;
    
    String mytime = self->GetTimeStampNow();
    mystamp = self->ToTimestamp(mytime);

    for (int i=0; i< programs; i++) {
        String sched = self->getScheduler(i);
        if (sched != "") {
            prgstamp = self->ToTimestamp(sched);
          
            if (mystamp == prgstamp) {
                // do things if matches
                DEBUGLOG(" TICK_MATCH! #%d %s %s\n", i, mytime.c_str(), sched.c_str());
                 self->setLastOpen(sched.c_str());
                 //self->AdvanceSlot();
                // CALL HERE THE CODE TO MOVE THE MOTOR:


            }
        }
    }
}

You should modify the _motor_moveto() code to do whatever you want (e.g. turn 3 times, etc).
see catfeeder.cpp.

 
// calls to function Move()
// dir: 0, 1
// steps: number of steps to move
// _motor is the motor stepper implementation
// you have to call the function in this way, to avoid blocking
schedule_function(std::bind(MotorStepperClass::Move, dir, steps, _motor));
  1. For my screw type cat feeder, I don't need a date data(DD-MM-YY) to feed the cat. Instead of that, I need ESP to act as a daily alarm(only time HH:MM: SS is needed) where every day at a certain time it will trigger.

See catfeeder.cpp and change the function to this:

String CatFeederClass::GetTimeStampNow() {
    time_t t = now(); 
    char *buf = (char *)malloc(1024);
    sprintf(buf, "%02d:%02d:%02d", hour(t), minute(t), second(t));
    String ret = buf;
    free(buf);
    return(ret);
}

See catfeeder.cpp and the function in order to use only the hour, minute second, as these:

unsigned long CatFeederClass::ToTimestamp(String d) {
    // EPOCH 01/01/1970 00:00:00
    // 1 hour	3600 seconds
    // 1 day	86400 seconds
    // 1 week	604800 seconds
    // 1 month (30.44 days) 	2629743 seconds
    // 1 year (365.24 days) 	 31556926 seconds

    int hour, minute, second;

    sscanf(d.c_str(),"%02d:%02d:%02d", &hour, &minute, &second);
    
    unsigned long ret;

    ret =  (hour * 3600) + (minute * 60) + second;
    
    return(ret);
}

Any suggestions on how to do that? you have done an awesome job btw.

Hope it works for you :-)
Kind Regards

@tmmsunny012
Copy link
Author

Sorry for replying to you so late. It took me long to figure out most of the codes. I have followed your steps and its kinda solve the issues. regarding the Telegram bot library. I couldn't find any code inside the catfeeder.cpp or cat feeder.h ..if I want to implement telegram bot where should I look for it in the codes. A few suggestions might help me a bit. Thanks again.

:)

@juanmcasillas
Copy link
Owner

Sorry for replying to you so late. It took me long to figure out most of the codes. I have followed your steps and its kinda solve the issues. regarding the Telegram bot library. I couldn't find any code inside the catfeeder.cpp or cat feeder.h ..if I want to implement telegram bot where should I look for it in the codes. A few suggestions might help me a bit. Thanks again.

:)

Telegram bot is in very preliminary support, but you shouldn't have any problems working
with it. For this reason, I remove it from the latest development release. If you wanna know
more about it, just clone the version 64e54b5e32a5e0781db92c703e64fabb9f1622d1
(initial release) this version has the code with the preliminary support.

Also check my Universal Telegram Bot fork.

Thanks in advance,

@tmmsunny012
Copy link
Author

tmmsunny012 commented Jan 28, 2020

Hi ,I copied the source files for running into telegram .It seems the the telegram bot you forked and changed for Json 6 is not compiling so far . I tried some changes and it compiles but not running the bot. I saw this in the bot.h .Do I need change bool _active =true ??
I did that and the esp started to crash.

I am attaching the modified bot codes for json 6

here.May be you can look into this .

protected:
WiFiClientSecure _client;
bool _active = false; Do I need to change it to true ?

    // interval configuration
    int Bot_lasttime = 0;
    int Bot_rcv_delay = 5000; // 1 second
    int last_message_received = 0;







@tmmsunny012
Copy link
Author

telegram_cpp.txt
telegram_h.txt

these are files... sorry for copy and pasting the code..it was bad idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants