Programming, Uncategorized

Uptime and ESP8266

Any time meassurement in ESP8266 is done through millis() function. A nice article about this topic is here. The article emphasis duration meassuremnt instead of timestamps. The modular arithmetic is going to bypass any rollover of unsigned long type used for millis() function. The rollover happens approximately each 47 days. If we need longer time we can increae it by using 64 bits:

uint64_t millis64() {
    static uint32_t low32, high32;
    uint32_t new_low32 = millis();
    if (new_low32 < low32) high32++;
    low32 = new_low32;
    return (uint64_t) high32 << 32 | low32;
}

If we do not need to measure seconds for uptime we can use unsigned long even for thousand years, by simplification to minutes. It is just necessary to use millis one time per minute (it is 60 000 ticks). The code could look like this:

unsigned long TT,upM=0,upH=0,upD=0;

if (millis()-TT >60000)
    {
      upM++;
      if (upM == 60) 
      {
        upM=0;
        upH++;
      }
      if (upH == 24)
      {
        upH=0;
        upD++;
      }
    }
Programming

Operator time for SIM800L

Module SIM800L is simple GSM modem, which could be connected via serial line (even SW serial). It could send/receive SMS and calls. The calls require connected microphone and speaker. SMS sending works fine without additional HW. A nice article (in Czech) is here. The modem needs good quality power input at 4.2V and peak current is 3A.

After power is applied the modem LED is blinking quickly about 10 times. Then it will be off for a while (modem is connecting to GSM network) and after successful connection the speed of LED blinking is slower. SIM should be inserted with contacts pointing to printed board.

Související obrázek

The modem worked fine if there was good power input. The only problem was with time synchronization  to operator’s time. Each sync has ended up with following time:

04/01/01,00:01:55+32

Any parameter change did not help. After some failures I have tried to change CBAND (Get and Set Mobile Operation Band ) parameter. The original setting was:

+CBAND: EGSM_MODE,ALL_BAND

The modem reported following options for CBAND parameter:

+CBAND: (EGSM_MODE,DCS_MODE,GSM850_MODE,PCS_MODE,EGSM_DCS_MODE, GSM850_PCS_MODE,EGSM_PCS_MODE,ALL_BAND)

I have tried “DCS_MODE” and it did not work, but the second try “EGSM_MODE” or “ALL_BAND” worked fine.

Change to EGSM_MODE:

at+cband=EGSM_MODE

OK

*PSUTTZ: 2018,10,31,17,15,19,”+4″,0

DST: 0

+CIEV: 10,”23002″,”CEZ”,”CEZ”, 0, 0

Change check:

at+cband?

+CBAND: EGSM_MODE

OK

and operator time is?

at+cclk?

+CCLK: “18/10/31,18:15:32+04”

After storing new settings into modem config (AT&W) the modem picks up the operator time immediately after power connection and connecting to GSM network.

Programming

D1 mini blinking built in LED

Today we have successfully controlled LED on D1 mini. D1 mini is cheap chip from China, which has wifi connectivity. You can program it via Arduino IDE. There is a simple code for built in LED control. LED is connected to port D4 of D1 mini.

void setup() {
// put your setup code here, to run once:
pinMode(D4, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(D4, HIGH);
delay(1000);
digitalWrite(D4, LOW);
delay(1000);
}

phone