Arduino Mega Serial and INT ->program hangs

Hello

I am exploring the ESP8266 using ITEAD ESP8266 library and need to have a interrupt working for another library called SensorReceiver. The app should receive wireless temperature and humidity data and send it to a custom web server using the WiFi ESP8266.

Now, every time an ESP8266 function is called, the program stops. I assume there is some incomaptibilty but alreday tried different INTx lines without success.

Here is the simple code:

#include <ESP8266.h>
#define SSID        "mySSID"
#define PASSWORD    "myPassword"
#define HOST_NAME   "myServerIP"
#define HOST_PORT   (80)

/*
 * This sketch receives and decodes data from a 433MHz thermo/hygro weather sensor.
 * The received data (temperature, humidity, channel) is echo
 *
 * Setup:
 * - Connect digital output of a 433MHz receiver to digital pin 2 of Arduino
 * - Enable the serial monitor at 115200 baud. 
 *
 */

#include <SensorReceiver.h>

ESP8266 wifi(Serial3); //also tried with Serial1 and SoftwareSerial on an UNO

void sendData(byte channel, int temp, short int humi){
  Serial.print("sendData...");
  //init ESP8266
  Serial.print("FW Version:");
  Serial.println(wifi.getVersion().c_str());
  //more code to come
}

void setup() {
  Serial.begin(9600);

  // Init the receiver on interrupt pin 0 (digital pin 2).
  // Set the callback to function "showTempHumi", which is called
  // whenever valid sensor data has been received.
  // MEGA: labeled PWM2, INT4 (mapped also as INT0), ARDUINO PIN 2
  // MEGA: PIN 18, INT4
  pinMode(2,INPUT);
  SensorReceiver::init(0, showTempHumi);
  Serial.println("Setup DONE");
  Serial.print("FW Version:");
  Serial.println(wifi.getVersion().c_str());
}

void loop() {
  Serial.println("Waiting...");
  // Empty! However, you can do other stuff here if you like.
  delay(5000);
}

void showTempHumi(byte *data) {
  SensorReceiver::disable();
  // is data a ThermoHygro-device?
  if ((data[3] & 0x1f) == 0x1e) {
    // Yes!

    byte channel, randomId;
    int temp;
    short int humidity;

    // Decode the data
    SensorReceiver::decodeThermoHygro(data, channel, randomId, temp, humidity);

    // Print temperature. Note: temp is 10x the actual temperature!
    Serial.print("Temperature: ");
//the program stops after printing the above
    Serial.print(temp / 10); // units
    Serial.print('.');
    Serial.print(temp % 10); // decimal

    // Print humidity
    Serial.print(" deg, Humidity: ");
    Serial.print(humidity);
    Serial.print("% REL");

    // Print channel
    Serial.print(", Channel: ");
    Serial.println(channel, DEC);   
    sendData(channel, temp, humidity);
  }
  SensorReceiver::enable();
}

Please help

~josef

    Serial.print("Temperature: ");
//the program stops after printing the above
    Serial.print(temp / 10); // units
    Serial.print('.');
    Serial.print(temp % 10); // decimal

In an interrupt service routine? Dream on.

Where did you get that code?

If the function showTempHumi() really is an Interrupt Service Routine it is very poorly written. The ideal ISR would be something like

void myISR() {
   pulseCount ++;
}

and even if it can't be that simple it should do all its business within, say, 100 microsecs or less. The faster the better.

You certainly should not have Serial.print stuff in an ISR.

...R