How to make a pocket hotspot power on if it is not

Hello guys!

I’m kind of new to this Blynk type of usage and i am not really aware of the Blynk.timer and Blynk.begin functions.
So maybe someone can help me out. I’ve found these similar problems on other threads but mine is a little bit different and i can’t sort it out. Testing is also painfull (takes so much time on each run) and i’ll tell you why:

I have a pocket 4g hotspot that only functions with the battery on (huawei e5577c) and does not have a typical switch for powering on/off. It works with a softbutton that you have to press for a while.

My idea is to have it on my car permanently on, but with some security features. I have flame and temp sensors that will cutoff the power , sensors that i monitor and control on the blynk app.
So here’s the catch: the hotspot only works with the batt on it, so i have a usb charger on a relay for 12V that is cut or powered through a TTL current on the hotspot itself. If the hotspot is on, the charger will be on too. If the hotspot is off, the charger is off too. Now:

If the charger starts before pressing the power , the hotspot will boot in charging mode, so no wifi. you have to wait a while and the press power again for it to boot as hotspot. I have done this with a timed relay so that it does not happen.

But for some reasons related to voltage drop when i start the car, sometimes it messes up and i have the hotspot on charge mode and not wifi.

I already made my code so that i can control the on/off softswitch of the hotspot. And it works. I use it for safety cut-out and it is nicely working.
The thing is that i need the ESP to know that if he can’t connect to wifi or blynk 40/60 seconds after booting, he has to change the pin 16 to high for 5 seconds (button press time needed to get it out of charge mode) , then put it low and wait another 40/60 seconds or until it connects and then proceed.

It’s easier said than done, i never can get pass the blynk begin part, and i tried the boolean connect but i never sort the part that i need it to loop the connection trial and button press if not succeeded.

Here’s my working code. It’s kinda messy, i guess.

When Pin16 is HIGH the hotspot button is pressing.

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************

  This sketch shows how to read values from Virtual Pins

  App project setup:
    Slider widget (0...100) on Virtual Pin V1
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <math.h>
// which analog pin to connect
#define THERMISTORPIN A0
// resistance at 25 degrees C
#define THERMISTORNOMINAL 54000
// temp. for nominal resistance (almost always 25 C)
#define TEMPERATURENOMINAL 25
// how many samples to take and average, more takes longer
// but is more 'smooth'
#define NUMSAMPLES 5
// The beta coefficient of the thermistor (usually 3000-4000)
#define BCOEFFICIENT 3950
// the value of the 'other' resistor
#define SERIESRESISTOR 9700
uint16_t samples[NUMSAMPLES];

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxx";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxx";
char pass[] = "xxxxxx";


BlynkTimer timer;
float FailsafeTemp;
float ActualTemp;
int PWSW;
int mailcontrol;
int flamecontrol;
int corvermelha;
int corazul;

// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V1

void myTimerEvent()
{

  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V1, tempreading());
  if (tempreading() >= 54) {
    if (corvermelha == 2) {
      Blynk.setProperty(V1, "color", "#D3435C");
      Serial.println("COR VERMELHA");
      corvermelha = 1;
      corazul = 2;
    }

  }
  if (tempreading() <= 55) {
    if (corazul == 2) {
      Blynk.setProperty(V1, "color", "#04C0F8");
      Serial.println("COR azul");
      corazul = 1;
      corvermelha = 2;
    }

  }
  if (flamecontrol != 0) {
    Blynk.virtualWrite(V3, flamecontrol );
    Serial.println("V2 Valor flamecontrol");
  }
  if (FailsafeTemp <= ActualTemp || flamecontrol == 1 || PWSW == 0)
  {
    Blynk.virtualWrite(V2, 1);
    Serial.println("V2 1");
    digitalWrite(16, HIGH);
    Serial.println("pin 16 high dentro da rotina do cutoff");
    //delay(10000);
    //digitalWrite(16, LOW);
    if (flamecontrol == 1 && mailcontrol == 0)
    {
      Blynk.email("x@me.com", "Smart WIFI Hotspot Notification: FIRE WARNING!", "FLAME DETECTION ACTIVATED");
      mailcontrol = 1;
    }
    if (FailsafeTemp <= ActualTemp && mailcontrol == 0)
    {
      Blynk.email("x@me.com", "Smart WIFI Hotspot Notification: TEMPERATURE CUT-OFF!", "TEMPERATURE ABOVE CUT-OFF LIMIT");
      mailcontrol = 1;
    }
    if (PWSW == 0 && mailcontrol == 0)
    {
      Blynk.email("x", "Smart WIFI Hotspot Notification: Manual APP Shutdown", "WIFI HOTSPOT Shutdown");
      mailcontrol = 1;
      //Blynk.virtualWrite(V5, 1);
    }
  }
  /*else {
      digitalWrite(16, LOW);
      Serial.println("p16 low dentro do else da rotina de cutoff");
     // Blynk.virtualWrite(V2, 0);
    }
  */
}

BLYNK_WRITE(V2)
{
  int pinValue = param.asInt();
  if (pinValue == 0) {
    digitalWrite(16, LOW);
    Serial.println("leitura valor v2 LOW");
  }
  else {
    digitalWrite(16, HIGH);
    Serial.println("leitura valor v2 high");
  }


}

BLYNK_WRITE(V0)
{
  float pinValue = param.asInt();
  Blynk.virtualWrite(V4, pinValue);
  Serial.println("virtualWrite V4 pinvalue dento do blinkwite v0");
  FailsafeTemp = pinValue;
}

BLYNK_WRITE(V5)
{
  int pinValue = param.asInt();
  if (pinValue == 1)
  {
    Blynk.virtualWrite(V2, 0);
    Serial.println("virtualWrite V2 para 0 pinvalue dento do blinkwite v5");
    digitalWrite(16, LOW);
    PWSW = 1;
  }
  else {
    digitalWrite(16, HIGH);
    Blynk.virtualWrite(V2, 1);
    Serial.println("virtualWrite V2 para 1 pinvalue dento do else do blinkwite v5");
    PWSW = 0;
  }

}



void setup()
{
  // Debug console

  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
  timer.setInterval(5000L, myTimerEvent);
  Serial.begin(9600);
  pinMode(16, OUTPUT);
  pinMode(4, INPUT);
  digitalWrite(16, LOW);
  PWSW = 1;
  mailcontrol = 0;
  flamecontrol = 0;
  Blynk.begin(auth, ssid, pass);
  FailsafeTemp = 65;
  corazul = 2;
  corvermelha = 2;
  Blynk.virtualWrite(V4, FailsafeTemp);
  Blynk.virtualWrite(V2, 0);
  Blynk.virtualWrite(V5, 1);
  Blynk.virtualWrite(V3, 0);
  Blynk.syncAll();

}



void loop()
{
  Blynk.run();
  timer.run();
  if (digitalRead(4) == 1) {
    flamecontrol = 1;
    digitalWrite(16, HIGH);

  }
}




float tempreading()                     // run over and over again
{
  uint8_t i;
  float average;

  // take N samples in a row, with a slight delay
  for (i = 0; i < NUMSAMPLES; i++) {
    samples[i] = analogRead(THERMISTORPIN);
    delay(10);
  }

  // average all the samples out
  average = 0;
  for (i = 0; i < NUMSAMPLES; i++) {
    average += samples[i];
  }
  average /= NUMSAMPLES;

  // Serial.print("Average analog reading ");
  //  Serial.println(average);

  // convert the value to resistance
  average = 1023 / average - 1;
  average = SERIESRESISTOR / average;
  // Serial.print("Thermistor resistance ");
  // Serial.println(average);

  float steinhart;
  steinhart = average / THERMISTORNOMINAL;     // (R/Ro)
  steinhart = log(steinhart);                  // ln(R/Ro)
  steinhart /= BCOEFFICIENT;                   // 1/B * ln(R/Ro)
  steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
  steinhart = 1.0 / steinhart;                 // Invert
  steinhart -= 273.15;                         // convert to C

  ActualTemp = steinhart;
  return steinhart;

}

Thanks a lot for your help.

1 Like

There is nothing wrong with using the old standby delay() within the beginning of setup (pre Blynk.begin(), etc.). Use pinmode(), delay() and digitalWrite() to do what you need for pin 16 and then have a delay long enough to settle things down before starting the rest of your setup.

i think you didn’t understand what he wants. (or maybe i do not understand :slight_smile:

but he tries to check if there is net connection or not, and do events based on this decision.

maybe:

and i guess he can not do this because of the blocking function of blynk begin…

By manipulating the digital pins with delays first, then that should set up the needed Hotspot…

Then this will be resolved with a delay for 40-60 seconds before running any Blynk connection commands.

maybe you’re right. but now i will go to sleep …for sure :wink:

1 Like

Hi guys,

wanek is correct,

I know my explanation is confusing because the whole system is also confusing.
The hotspot can be physically powered on to charge mode without having anything to do with the ESP, like if the hotspot and ESP were “out of sync”, it’s just not every time that it happens. But when it does i have no method for the ESP to “understand” that the hotspot is charging and to try turn it of if he cannot connect at the first time.

I saw the links:

Blynk Library for Arduino v0.4.1 is released

so given the changes in 0.4.1 does that mean the Blynk.begin will wait forever until it connects to a Blynk server (or is there a configurable time-out parameter, either in Blynkconfig.h or local blynkserver) ?
community.blynk.cc

Location of Blynk.config() vs Blynk.connect()

Mine even blocks when the connection drops (which I want, but can be changed via the Blynk.config() method). New features: - Blynk.begin() now blocks until server is connected Edit: A real-world use case… I have many sensors all over the…

I do know that there are different ways to start. i’ve seen here on the forum a code for first connecting wifi and then connect to blynk, which seemed the way to go but i cannot implement it. I’m missing on examples to fully understand how it works, and i can’t think of a way to “time” the button presses in between.

thank you all!

Yes, I guess your overall situation and question is unclear (at least to me :wink: ) But lets try again…

Some of those articles you are referring to are about trying to do something on an ESP used as a WiFi shield for another MCU… and currently it appears that is not possible.

So, as long as you are using an ESP as the dedicated Blynk MCU and NOT as a WiFi shield for another Blynk MCU, then you should be able to simply Boot up, wait a set duration, use Blynk.connectWiFi(ssid, pass); to connect to WiFi, then whenever you are ready, run Blynk.config(auth, server, port); then either Blynk.run() or Blynk.connect() to start the Blynk <–> Server connection (through your previously setup WiFi).

And if the connection doesn’t go through after a specified timeout, you could program a complete retry via a board reset.

I have no idea about the button presses… I am guessing this is an attempt to have the ESP turn on the Hotspot automatically?? But what turns on the ESP?? Anyhow, if so, then my previous suggestion with delays and digital pins, pre Blynk.connectWiFi(ssid, pass); should still work.

Yes, I guess your overall situation and question is unclear (at least to me :wink: ) But lets try again…

Yeah, i believe i’m not the best in expressing myself, but the situation itself on text is hard to explain.
So here’s a little image if it makes it easier!! :grin:

Sometimes when i start the car the peak voltage makes component #2 have some false trigger and it shuts down the hotspot but the charge relay (component3) stays on. So hotspot starts charging and not functioning as a hotspot. So ESP can be on but cannot connect. BUT it only happens every so often, is not based on a pattern. It’s a “erratic” behaviour.

So, as long as you are using an ESP as the dedicated Blynk MCU and NOT as a WiFi shield for another Blynk MCU, then you should be able to simply Boot up, wait a set duration, use Blynk.connectWiFi(ssid, pass); to connect to WiFi, then whenever you are ready, run Blynk.config(auth, server, port); then either Blynk.run() or Blynk.connect() to start the Blynk ↔ Server connection (through your previously setup WiFi).

This is the approach i’ve been testing but i fail at something because connectWiFi timeout is one thing and then i need to put the pin 16 HIGH for 4 or 5 seconds, release it and be on connection attempt again.
I’ve read this approach and i thought i could work my way on it but i am not being successfull and i really don’t know where am i stuck. The code i’ve uploaded before is the actual working without this connection failsafe.

Thanks for your time Gunner

it is not a coding solution, but as size and weight doesn’t matter in this application did you try to hook up a really big cap near the hotspot? that should prevent to reboot. find the biggest 25v polarised cap you can get and try. it should work.

wanek8m
it is not a coding solution, but as size and weight doesn’t matter in this application did you try to hook up a really big cap near the hotspot? that should prevent to reboot. find the biggest 25v polarised cap you can get and try. it should work.

Hello!
I think i will not be needing it as Component #1 has one big capacitor on the inside, i think for filtering these kind of situations.
For somehow while i was testing this the erratic behaviour showed up, having the ESP “out of sync” with the internet. And i had to open the box, reset the ESP (as when it resets pulls the pins HIGH so it acts like i’m pressing power button on the hotspot) and there it goes online again.

Since starting is more likely to cause a drain than a peak, perhaps use one of those 0.5 - 1 Farad “stiffening” caps, from the automotive music industry, to parallel the main 12v feed to this whole ensemble.

1 Like