ESP822 TO WRITE TO SQL USING A WEB SERVICE

I am trying to record temperature I get from the sensor into my SQL database using a ASP.net web service. I know my web service is working fine because I have written an application on ASP.net to test it and I see data recorded in my SQL database. For now, there is just a link to the action AddRow on the page you get when you go to www.XXXX:8080/Webservice.asmx and when you click on the link you get to a page where there is an invoke button and when you click on that a constant gets written to the database. When I try the same with my arduino code, I get the following but nothing gets written to the database:

Working to connect.Feather Huzzah ESP8266 & BME280 Temperature, Humidity, Pressure and Altitude Server
Connected to XXXX
IP address: 192.168.1.81
connecting...
X.X.X.X
disconnecting.

Soft WDT reset

ctx: cont
sp: 3ffef4d0 end: 3ffef6b0 offset: 01b0

stack>>>
3ffef680: 00000000 3ffee658 3ffee490 40201e3c
3ffef690: 3fffdad0 00000000 3ffee67c 402033c4
3ffef6a0: feefeffe feefeffe 3ffee690 40100718
<<<stack<<<

ets Jan 8 2013,rst cause:2, boot mode:(1,6)

ets Jan 8 2013,rst cause:4, boot mode:(1,6)

wdt reset

I am connecting to WiFi and connecting to a remote server where the database is kept.

#include <SPI.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <Wire.h>

String z = "a";
IPAddress ip (192, 168, 1, 81);
IPAddress gateway (192, 168, 1, 1);
IPAddress subnet (255, 255, 255, 0);

//Internet Settings for 
const char* ssid     = "XX";
const char* password = "XX";


byte mac[] = {  0xEC, 0xFA, 0xBC, 0x05, 0xA4, 0x1A };

byte server[] = {X, X, X, X};


WiFiClient client;

void setup() {
digitalWrite(LED_BUILTIN, LOW);  // Turn the LED on by making the voltage LOW
Serial.begin(115200);

// Connect to WiFi network
WiFi.begin(ssid, password);
WiFi.config(ip, gateway, subnet);
Serial.print("\n\r \n\rWorking to connect");

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

Serial.println("Feather Huzzah ESP8266 & BME280 Temperature, Humidity, Pressure and Altitude Server");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("connecting...");

IPAddress server(X,X,X,X);
Serial.print(server);
if (client.connect(server,8080)) {
  
  client.println(F("POST /WebService.asmx HTTP/1.1"));
  client.println(F("Host: X.X.X.X:8080"));

  client.println(F("Content-Type: text/xml; charset=utf-8"));
  client.println(F("Content-Length: 350"));

  client.println(F("Connection: close"));
  client.println(F("SOAPAction: \"http://X.X.X.X:8080/webservices/AddRow\""));
  client.println();
  client.println(F("<?xml version=\"1.0\" encoding=\"utf-8\"?>"));
  client.println(F("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"));
 
  client.println(F("<soap:Body>"));
  client.println(F("<AddRow xmlns=\"http://X.X.X.X/webservices\">"));
  client.println(F("</AddRow>"));
  client.println(F("</soap:Body>"));
  client.println(F("</soap:Envelope>"));

  
} else {
  Serial.println("connection failed");
}

}
void loop() {
// put your main code here, to run repeatedly:


while(client.available()) {

  char c = client.read();
  Serial.print(c);
  
}

if (!client.connected()) {
  Serial.println();
  Serial.println("disconnecting.");
  client.stop();
  for(;;)
    ;
}

}

There is a smiley at the end of your code... can’t work

Sorry about that, I fixed the last part where it says "for(;; )" and put a space between the ; and ) to it would not turn it into a smiley.

yasemin27:
Sorry about that, I fixed the last part where it says "for(;; )" and put a space between the ; and ) to it would not turn it into a smiley.

Or you could just use [code][/code] tags, please read the sticky 'How to use this forum' post.

for(;;);

That's just asking for the watch dog to bite ...

Pieter

just fixed it sorry

Not sure about the other problem but this problem

Soft WDT reset

ctx: cont 
sp: 3ffef4d0 end: 3ffef6b0 offset: 01b0

>>>stack>>>
3ffef680:  00000000 3ffee658 3ffee490 40201e3c  
3ffef690:  3fffdad0 00000000 3ffee67c 402033c4  
3ffef6a0:  feefeffe feefeffe 3ffee690 40100718  
<<<stack<<<

ets Jan  8 2013,rst cause:2, boot mode:(1,6)


ets Jan  8 2013,rst cause:4, boot mode:(1,6)

wdt reset

is likely caused by this line

while(client.available()) {   //SOURCE OF PROBLEM HERE

  char c = client.read();
  Serial.print(c);
  
}

You need to get your client initialized

I thought I was already initializing the client using this:

WiFiClient client;

That’s instantiating it

When you write server code you usually do something like this in the loop

// Check if a client has connected
  WiFiClient client = server.available();
  if (client) {
    Serial.println("new client");
    ...
  }

J-M-L:
That’s instantiating it

When you write server code you usually do something like this in the loop

// Check if a client has connected

WiFiClient client = server.available();
  if (client) {
    Serial.println("new client");
    ...
  }

this is irrelevant. his Client is a client, not a server request handler

Juraj:
this is irrelevant. his Client is a client, not a server request handler

You are correct - I had not read OP’s code in details, was just assuming OP was waiting for connexions

The issue is actually in for(;;);

An ESP has two watchdogs (a hardware one and a software one) - timers that are counting in the background and if they overflow will reset your ESP.

Your code should not lock up the loop() for too long without giving a chance for the watchdog to be fed (you can do this manually with a ESP.wdtFeed();) otherwise it barks at you.

You can disable the software watchdog timer with ESP.wdtDisable() but there is still the hardware watchdog looking at what you do - for example

void setup() {
 ESP.wdtDisable();
 while (true);
}
 
void loop(){}

will trigger the hardware watchdog, and you’ll see the crash log is printed to the serial port mentioning wdt reset and the reset cause has the number 4, which is the hardware watchdog reset indication.

Long story short - don’t lock up your code in an infinite loop without feeding the dog and read the documentation about watchdogs

For example this should not crash (writing on my tablet, can’t try out - might need the usual ESP8266 include)

void setup() {
 while (true) ESP.wdtFeed(); // infinite loop but feed the dog
}

void loop(){}

Hope this helps