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

Sometimes, the before() is not called. #16

Open
njbuch opened this issue Dec 8, 2017 · 5 comments
Open

Sometimes, the before() is not called. #16

njbuch opened this issue Dec 8, 2017 · 5 comments
Assignees

Comments

@njbuch
Copy link
Contributor

njbuch commented Dec 8, 2017

I have realized that the reason for some erronous readings from some sensors, is due to the fact that the sensor-init is never done.

MC[I]: Booting ESP8266 device...
MC[I]: WIFI not connected, trying connection...
MC[I]: Connecting to WiFi with ssid[1421530] and with password............OK
MC[I]: WiFi BSSID:[00:02:61:A8:32:58], RSSI:[-68 dBm, 64 %], IP:[192.168.1.148], StatusCode:[3]
MC[I]: Configuration(NodeEUI:[ESP_2D5A26], Mqtt{mDNS-status:[0], Server:[192.168.1.197], Port:[1883], FeedId:[esp], User:[]})
MC[I]: MQTT settings(Broker:[192.168.1.197], Port:[1883])
MC[I]: MQTT authenticating as anonymous
MC[I]: MQTT connection failed, rc=-4
MC[I]: Initialization done...
MC[I]: MQTT failed! Retryting to connect...
MC[I]: MQTT settings(Broker:[192.168.1.197], Port:[1883])
MC[I]: MQTT authenticating as anonymous
MC[I]: MQTT connected :)
MC[I]: MQTT topic subscribed:[in_esp/ESP_2D5A26/#]
Envoie de Luxmeter:81
Temp2: 93
Requesting temperatures...DONE
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60
Envoie de Luxmeter:81
Temp2: 93

It seems that the device starts probing sensors without the before() or setup() is called. In the above, these two functions are declared:

void setup() {
    MC_SERIAL.print("Core: Setup running... ");
}

and

void before() {
    MC_SERIAL.print("Core: Before running... ");
[init code goes here]
}
@njbuch
Copy link
Contributor Author

njbuch commented Dec 8, 2017

Could be related to the other issue about a failed MQTT connection?

@jkandasa jkandasa self-assigned this Dec 8, 2017
@jkandasa
Copy link
Member

jkandasa commented Dec 8, 2017

@njbuch I will check and update you

@jkandasa
Copy link
Member

jkandasa commented Dec 8, 2017

@njbuch This is the sequence,

  1. Setup
  2. loop-> mc.loop()->before()->loop
  3. loop

In your example, the serial port is no initialized in setup. It is initialized when calling mc.loop()

@njbuch
Copy link
Contributor Author

njbuch commented Dec 10, 2017

I can confirm the sequence you write, when the device is booted first time after flash, but if the device is off and then powered on, the before() is never called and sensors does not work....

@njbuch
Copy link
Contributor Author

njbuch commented Dec 13, 2017

No worries on this one, I have solved it by:

void loop() {

  // This is required for the Mycontroller device works...

  mc.loop();

  //You can add your logic here.

   if(!custom_initdone)

  {
    custom_init();
  }

  sendMeasurements();

}

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