I am using a nodeMCU to send data to my local web page developed using Spring boot but when I run the code I don't get an error the esp8266 connects to WiFi but I don't get anything on my spring boot app or any responses. Here is the rest controller used from spring boot
@RestController
@RequestMapping("/getallcadres")
public class cadreController {
@Autowired
cadreRepository cadre;
@PostMapping("/getnbpassage")
public String getnbrpassage(@RequestBody String nb){
System.out.println("nombre de passage = "+nb);
return "received";
}
}
and the Arduino code
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
void setup() {
Serial.begin(9600);//Serial connection
WiFi.disconnect();
WiFi.begin("Iphone de elaa", "27343550"); //WiFi connection
while (WiFi.status() != WL_CONNECTED) { //Wait for the WiFI connection completion
delay(500);
Serial.println("Waiting for connection");
}
Serial.println("Wifi is connected");
Serial.println(WiFi.localIP());
}
void loop() {
if(WiFi.status()== WL_CONNECTED){ //Check WiFi connection status
Serial.println("here we start");
HTTPClient http; //Declare object of class HTTPClient
http.begin("http://localhost:8080/getallcadres/getnbpassage"); //Specify request destination
http.addHeader("Content-Type", "text/plain"); //Specify content-type header
int httpCode = http.POST("5"); //Send the request
String payload = http.getString();//Get the response payload
Serial.println("return code"+httpCode); //Print HTTP return code
Serial.println(payload); //Print request response payload
http.end(); //Close connection
}else{
Serial.println("Error in WiFi connection");
}
delay(30000); //Send a request every 30 seconds
}
