nodeMCU 1.0 (ESP-12E) resets when sending to thingspeak

hello,

i am trying to make my nodeMCU send temperature data to thingspeak. with any other script the microcontroller works fine (web server etc.) but when i use the thingspeak-command “ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey)” the board resets with an error code on the serial port:

ets Jan 8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x4010f000, len 1264, room 16
tail 0
chksum 0x42
csum 0x42
~ld

i´ve isolated the above command to be the source of the problem, when i comment it out everything works fine.

thanks a lot for any suggestions.
jochen

my code is this :

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"
#include "ThingSpeak.h"

#define DHTPIN 5     // what digital pin we're connected to

unsigned long myChannelNumber = xxx;
const char * myWriteAPIKey = "xxx";

#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

#include <ESP8266WiFiMulti.h>

//ESP8266WiFiMulti WiFiMulti;
void setup() {
  Serial.begin(9600);

  // We start by connecting to a WiFi network

  WiFi.begin("ssid", "key");
  Serial.println();
  Serial.println();
  Serial.print("Wait for WiFi... ");

  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  delay(500);

  Serial.println("DHT22 test!");
  WiFiClient client;
  ThingSpeak.begin(client);

}

void loop() {
  dht.begin();

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index in Celsius
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.println(" *C ");
  delay (1000);
  ThingSpeak.setField(1, t);
  ThingSpeak.setField(2, h);
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);

  // Wait a few seconds between measurements.
  delay(60000);
}

You are passing a WiFiClient object to ThingSpeak.begin that goes out of scope at the end of setup.

void setup() {
//...
  WiFiClient client;
  ThingSpeak.begin(client);
}

make it global.

hi whandall, thanks a lot, that really helped me.now it works:-) greets jochen