Arduino ethernet shield doesn't send data - REST API - arduino

I have a little problem with function GET function of HTTP. The program reads ID number, and after enter(new line), it should get data from REST API. Problem is that I have to press enter twice for data from API. Here is code
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x90, 0x02, 0xBA, 0xEF, 0xCA, 0x33 };
char server[] = "xxx.xx";
EthernetClient client;
char tmp;
char buffer[30];
int bufferCounter = 0;
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
}
delay(1000);
Serial.println("Ready");
}
void getData(char* num ){
Serial.println("connecting...");
if (client.connect(server, 80)) {
Serial.println("connected");
client.print("GET /api/id/");
client.print(num);
client.println("/?format=json HTTP/1.1");
client.println("Host: xxx.xx");
client.println("Authorization: Token xxxxxxxxxxxxxxxxxxxxx");
client.println("Connection: close");
client.println();
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
while (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
}
}
void loop() {
if (Serial.available() > 0) {
tmp = Serial.read();
if(tmp == '\n'){
buffer[bufferCounter] = 0;
bufferCounter = 0;
Serial.println(buffer);
getData(buffer);
}
else{
buffer[bufferCounter] = tmp;
bufferCounter++;
}
}
}
On the serial link I get this message. At first
Ready
when I write there 35 and press enter I get this
35
connecting...
connected
then I have to press enter again, and finally I get the correct data but with connection failed and I dont know why
connecting...
connection failed
HTTP/1.1 404 NOT FOUND
Date: Tue, 22 Nov 2016 16:18:18 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS
Vary: Accept, Cookie
18
{"detail":"not found."}
0
disconnecting.
Could someone help me, where is the problem? Thank you.

Related

Communication between Postman and Arduino

I plan to send from a server a POST request to my Arduino Uno WiFi Rev2. More correctly, when the server sends this request a servomotor controlled by the Arduino should start moving. Right now, I'm using Postman to try and connect with the Arduino but I can't get it to work. So first I connect the Arduino to WiFi using my smartphone as a hotspot. This should be the unit's IP address, right?
I then try to send a POST request to this IP but it doesn't work. I'm also unsure which port number I should use, so I have just been trying with the standard ones (80, 4430, etc).
What am I doing wrong and how should I proceed?
EDIT: Here is my code.
#include <SPI.h>
#include <Servo.h>
#include <WiFiNINA.h>
char ssid[] = "MyNetwork"; // The network SSID
char pass[] = "testtest"; // The network password
int status = WL_IDLE_STATUS; // The Wifi radio's connection status
Servo servo_9; // Initializes the servomotor
WiFiServer server(80); // Server socket
//WiFiClient client;
WiFiClient client = server.available();
void setup() {
// Connects the servomotor to pin 9
servo_9.attach(9, 500, 2500);
// Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // Wait for serial port to connect. Needed for native USB port only
}
enable_WiFi();
connect_WiFi();
server.begin();
printCurrentNet();
printWifiData();
}
void loop() {
// Check the network connection once every 10 seconds:
delay(10000);
client = server.available();
if(client){
printWEB();
}
}
void enable_WiFi(){
// Check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// Don't continue
while (true);
}
// Check if the latest Firmware version is installed
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
}
void connect_WiFi(){
// Attempt to connect to Wifi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
// Wait 10 seconds for connection:
delay(10000);
}
// Now the arduino is connected, so print out the data:
Serial.print("You're connected to the network: ");
Serial.println();
}
void printCurrentNet() {
// Print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// Print the MAC address of the router you're attached to:
byte bssid[6];
WiFi.BSSID(bssid);
Serial.print("BSSID: ");
printMacAddress(bssid);
// Print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("Signal strength (RSSI): ");
Serial.println(rssi);
// Print the encryption type:
byte encryption = WiFi.encryptionType();
Serial.print("Encryption Type: ");
Serial.println(encryption, HEX);
Serial.println();
}
void printWifiData() {
Serial.println("Your board's IP and MAC address: ");
// Print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// Print your MAC address:
byte mac[6];
WiFi.macAddress(mac);
Serial.print("MAC address: ");
printMacAddress(mac);
Serial.println();
}
// Find the MAC adress for your Arduino board
void printMacAddress(byte mac[]) {
for (int i = 5; i >= 0; i--) {
if (mac[i] < 16) {
Serial.print("0");
}
Serial.print(mac[i], HEX);
if (i > 0) {
Serial.print(":");
}
}
Serial.println();
}
void printWEB() {
if (client) { // if you get a client,
Serial.println("new client"); // print a message out the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
// The HTTP response ends with another blank line:
client.println();
// break out of the while loop:
break;
}
else { // if you got a newline, then clear currentLine:
currentLine = "";
}
}
else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
}
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}
void servomotorGate(){
int position = 0;
for (position = 0; position <= 90; position += 1) {
servo_9.write(position);
Serial.println("Opening the gate");
}
delay(5000); // Wait for 5000 millisecond(s)
for (position = 90; position >= 0; position -= 1) {
servo_9.write(position);
Serial.println("Closing the gate");
}
}
I added the server client to listen for connections. However, the main reason why I couldn't connect to my IP address with Postman was that I was trying to get WiFi from my phone as a hotspot. I guess there is a problem with the port forwarding when using a hotspot. In the end, I solved the issue by connecting to a normal router WiFi network.

Calling nest api with esp8266 using arduinoEDK

I'm trying to connect to the nest_API (thermostat) using ESP8266 and the Arduino EDK. But so far with no result.
I've seen somebody asking the same question here before. But the answer to his problem didn't help me.
So here's my code:
Code
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
const char* ssid = "xxxxx";
const char* password = "xxxxx";
const char* host = "developer-api.nest.com";
const int httpsPort = 443;
const char* BearerKey = "xxxxxxxuB0QSbgw2nsT85dJEHRpwvR7rSyrLHm2E54QpC9vnSzB5PV8OtGDPm0mAh96wgM0MwApmS";
//declaring GPIO's
int gpio13Led = 13;
int gpio12Relay = 12;
// Use web browser to view and copy
// SHA1 fingerprint of the certificate
const char* fingerprint = "87:CB:F2:E6:44:C0:AA:F2:4C:28:B2:97:85:70:18:92:45:1B:A4:57";
void setup() {
// preparing GPIOs
pinMode(gpio13Led, OUTPUT);
digitalWrite(gpio13Led, HIGH);
pinMode(gpio12Relay, OUTPUT);
digitalWrite(gpio12Relay, HIGH);
Serial.begin(115200);
Serial.println();
Serial.print("connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
// Use WiFiClientSecure class to create TLS connection
WiFiClientSecure client;
Serial.print("connecting to ");
Serial.println(host);
if (!client.connect(host, httpsPort)) {
Serial.println("connection failed");
return;
}
if (client.verify(fingerprint, host)) {
Serial.println("certificate matches");
digitalWrite(gpio13Led, LOW);
} else {
Serial.println("certificate doesn't match");
}
String url = "/";
Serial.print("requesting URL: ");
Serial.println(url);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Content-Type: application/json\r\n" +
"Authorization: Bearer " + BearerKey + "\r\n\r\n"
);
Serial.println("request sent");
while (client.connected()) {
String line = client.readStringUntil('\n');
Serial.println(line);
if (line == "\r") {
Serial.println("headers received");
break;
}
}
while (client.available()) {
String line = client.readStringUntil('\n');
Serial.println("reply was:");
Serial.println("==========");
Serial.println(line);
Serial.println("==========");
Serial.println("closing connection");
}
}
void loop() {
}
I never get any result from the server. But when I'm using postman, it works. So I wonder. Do I need to use the "host: " + host + ... line?
And is there a way to catch some errors with the WiFiClientSecure.h library.
I also once changed the url for host in the get string.
Then I received one error from the server. I was already happy there was a response after all.
Serial output
connecting to xxxxx
........
WiFi connected
IP address:
xxxxx
connecting to developer-api.nest.com
certificate matches
requesting URL: /
request sent
HTTP/1.1 307 Temporary Redirect
Content-Type: application/json; charset=UTF-8
Access-Control-Allow-Origin: *
Cache-Control: private, no-cache, no-store, max-age=0
Pragma: no-cache
Location: https://firebase-apiserver10-tah01-iad01.dapi.production.nest.com:9553/
Connection: close
Authorization: Bearer xxxxx
content-length: 0
headers received
reply was:
==========
==========
closing connection
Now I'm completely stuck. It would be nice if somebody could help me further out. thx
Wow. Holy smoke! I've got a response! You're tip made it work #gre_gor.
I've changed the host name and the port because my reply said something like this.
Here's my final code:
CODE:
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
const char* ssid = "xxxxx";
const char* password = "xxxxx";
const char* host = "firebase-apiserver10-tah01-iad01.dapi.production.nest.com";
const int httpsPort = 9553; //443;
const char* BearerKey = "xxxxx";
//declaring GPIO's
int gpio13Led = 13;
int gpio12Relay = 12;
// Use web browser to view and copy
// SHA1 fingerprint of the certificate
const char* fingerprint = "87:CB:F2:E6:44:C0:AA:F2:4C:28:B2:97:85:70:18:92:45:1B:A4:57";
void setup() {
// preparing GPIOs
pinMode(gpio13Led, OUTPUT);
digitalWrite(gpio13Led, HIGH);
pinMode(gpio12Relay, OUTPUT);
digitalWrite(gpio12Relay, HIGH);
Serial.begin(115200);
Serial.println();
Serial.print("connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
// Use WiFiClientSecure class to create TLS connection
WiFiClientSecure client;
Serial.print("connecting to ");
Serial.println(host);
if (!client.connect(host, httpsPort)) {
Serial.println("connection failed");
return;
}
if (client.verify(fingerprint, host)) {
Serial.println("certificate matches");
digitalWrite(gpio13Led, LOW);
} else {
Serial.println("certificate doesn't match");
}
String url = "/";
Serial.print("requesting URL: ");
Serial.println(url);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Content-Type: application/json\r\n" +
"Authorization: Bearer " + BearerKey + "\r\n\r\n"
);
Serial.println("request sent");
while (client.connected()) {
String line = client.readStringUntil('\n');
Serial.println(line);
if (line == "\r") {
Serial.println("headers received");
break;
}
}
while (client.available()) {
String line = client.readStringUntil('\n');
Serial.println("reply was:");
Serial.println("==========");
Serial.println(line);
Serial.println("==========");
Serial.println("closing connection");
}
}
void loop() {
}
Serial monitor:
connecting to xxxxx
...........
WiFi connected
IP address:
xxxxx
connecting to firebase-apiserver10-tah01-iad01.dapi.production.nest.com
certificate doesn't match
requesting URL: /
request sent
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Access-Control-Allow-Origin: *
Cache-Control: private, no-cache, no-store, max-age=0
Pragma: no-cache
Connection: close
content-length: 8060
headers received
reply was:
==========
{"devices":{"thermostats":{"exxx":{"humidity":40,"locale":"nl-NL","temperature_scale":"C","is_using_emergency_heat":false,"has_fan":false,"software_version":"5.6.6-4","has_leaf":true,"where_id":"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7XyH-9WDdVgA","device_id":"e97ayjdpIOkPa4vZFxHggZMXiHKfhsyU","name":"Downstairs","can_heat":true,"can_cool":false,"target_temperature_c":15.0,"target_temperature_f":59,"target_temperature_high_c":24.0,"target_temperature_high_f":75,"target_temperature_low_c":20.0,"target_temperature_low_f":68,"ambient_temperature_c":15.5,"ambient_temperature_f":61,"away_temperature_high_c":24.0,"away_temperature_high_f":76,"away_temperature_low_c":8.5,"away_temperature_low_f":48,"eco_temperature_high_c":24.0,"eco_temperature_high_f":76,"eco_temperature_low_c":8.5,"eco_temperature_low_f":48,"is_locked":false,"locked_temp_min_c":20.0,"locked_temp_min_f":68,"locked_temp_max_c":22.0,"locked_temp_max_f":72,"sunlight_correction_active":false,"sunlight_correction_enabled":true,"structure_id":"vEJb634MNif-xxx{"access_token":"xxxx","client_version":2,"user_id":"xxxx"}}
==========
closing connection
The weird thing is that my fingerprint doesn't match but that it still proceeds to give me information.
Next step is to read this response and use the data I want. :-)

400 Bad Request arduino esp8266

Hi i am trying to test a value form nodemcu board i am using arduino ide to code and have modified the WIFIClient example to send a value to my localhost using GET. it gives me bad request error. any help or suggestion is appreciated
Modified WIFIClinet
#include <ESP8266WiFi.h>
const char* ssid = "ssid";
const char* password = "pwd";
const char* host = "http://10.0.0.39/edu/arduino.php";
void setup() {
Serial.begin(115200);
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
int value = 0;
void loop() {
delay(5000);
++value;
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// We now create a URI for the request
String url ="?v=we";
//
//
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
//
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
}
Output from serial monitor
connecting to http://10.0.0.39/edu/arduino.php
Requesting URL: ?v=we
HTTP/1.0 400 Bad Request
Server: httpd
Date: Sat, 01 Jan 2011 22:02:19 GMT
Content-Type: text/html
Connection: close
<HTML><HEAD><TITLE>400 Bad Request</TITLE></HEAD>
<BODY BGCOLOR="#cc9999"><H4>400 Bad Request</H4>
Bad filename.
</BODY></HTML>
I hope this is helpful for people running this on local host i changed
const char* host = "http://10.0.0.39/edu/arduino.php";
to
const char* host = "10.0.0.39";
and
String url ="?v=we";
to
String url ="/edu/arduino.php?v=we";

arduino find text in webpage

I am trying to make an arduino weather alert, from this website
and I need to find the contents of the quotation marks in "weather" after "main". I have looked for a text finder, but the one on the arduino website but it's so undescriptive that it might as well not exist.
Currently my code looks like this:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "api.openweathermap.org";
IPAddress ip(192,168,1,77);
EthernetClient client;
void setup() {
Serial.begin(9600);
while (!Serial) {
;
}
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
}
delay(1000);
if (client.connect(server, 80)) {
client.println("GET /data/2.5/weather?q=Melbourne,au HTTP/1.1");
client.println("Host: api.openweathermap.org");
client.println("Connection: close");
client.println();
}
else {
}
}
void loop()
{
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
client.stop();
while(true);
}
}
and it returns:
HTTP/1.1 200 OK
Server: nginx
Date: Sun, 07 Jun 2015 21:17:44 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: close
X-Source: redis
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST
1d2
{"coord":{"lon":144.96,"lat":-37.81},"sys":{"message":0.0117,"country":"AU","sunrise":1433626204,"sunset":1433660872},"weather":[{"id":800,"main":"Clear","description":"Sky is Clear","icon":"01n"}],"base":"stations","main":{"temp":284.532,"temp_min":284.532,"temp_max":284.532,"pressure":1011.27,"sea_level":1030.68,"grnd_level":1011.27,"humidity":80},"wind":{"speed":4.43,"deg":331.501},"clouds":{"all":0},"dt":1433711139,"id":2158177,"name":"Melbourne","cod":200}
0
for this output I want it to say: Clear
A very easy way to get the data you want is with TextFinder from the Arduino playground. I believe this should work. Note that I haven't tested it, so fingers crossed.
Add this at the begining
#include <TextFinder.h>
#include <String.h>
String result = "";
TextFinder finder( client );
Then modify your loop() to this
if (client.connected()){
finder.find("\"weather\"");
finder.find("\"main\":\"");
char c = client.read();
while(c != '\"'){
result += c;
c = client.read();
}
Serial.print(result);
}
if (!client.connected()) {
Serial.println();
client.stop();
while(true);
}
More info below if you're interested.
The response you're getting is json, to properly interpret it you need a json parser. I found a library on github: ArduinoJson that parses json on the arduino. It seems quite easy to use too. If you need help with it, you can browse it's wiki
Before you start parson the json, you need to first strip the header from the response. To do that you could keep reading the characters until you get a double CRLF (\r\n\r\n)

Arduino module esp8266 returns bad request

I am testing the wifi module esp8266 with my arduino uno.
I made it work with direct connection RX/TX and through softwareserial.
This is my code:
#include <SoftwareSerial.h>
SoftwareSerial esp8266(3, 2); // RX | TX
#define DEBUG true
int ERROR_PIN = 7;
int OK_PIN = 6;
char serialbuffer[400];//serial buffer for request url
const String ssid = "XXX";
const String pw = "XXX";
int state = 0;
void setup()
{
delay(1000);
/**
// init leds
pinMode(ERROR_PIN, OUTPUT);
pinMode(OK_PIN, OUTPUT);
state = 0;
digitalWrite(ERROR_PIN, HIGH);
digitalWrite(OK_PIN, LOW);
/**/
// init ports
Serial.begin(19200);
Serial.println("initializing esp8266 port...");
esp8266.begin(19200);
delay(400);
// init WIFI
/**/
while(!esp8266.available())
{
Serial.print("...");
delay(300);
}
Serial.println();
Serial.println("FINISH esp8266 initializing!");
//
/**
digitalWrite(ERROR_PIN, LOW);
digitalWrite(OK_PIN, HIGH);
state = 1;
/**/
/**/
// Setup connection
sendData("AT+RST\r\n",2000,DEBUG);
sendData("AT+CWMODE?\r\n",1000,DEBUG);
//sendData("AT+CWMODE=1\r\n",2000,DEBUG);
//sendData("AT+RST\r\n",3000,DEBUG);
//sendData("AT+CWLAP\r\n",6000,DEBUG);
sendData("AT+CWJAP=\"" + ssid + "\",\""+ pw +"\"\r\n",12000,DEBUG);
sendData("AT+CIFSR\r\n",8000,DEBUG);
sendData("AT+CIPMUX=1\r\n", 6000, DEBUG);
webRequest("");
/**/
/**/
}
void loop()
{
if (esp8266.available())
{
char c = esp8266.read() ;
Serial.print(c);
/**
if(state == 0)
{
state = 1;
digitalWrite(ERROR_PIN, LOW);
digitalWrite(OK_PIN, HIGH);
}
/**/
}
else
{
/**
if(state > 0)
{
state = 0;
digitalWrite(ERROR_PIN, HIGH);
digitalWrite(OK_PIN, LOW);
}
/**/
}
if (Serial.available())
{
char c = Serial.read();
esp8266.print(c);
}
}
//////////////////////////////////////////////////////////////////////////////
String sendData(String command, const int timeout, boolean debug)
{
String response = "";
esp8266.print(command); // send the read character to the esp8266
long int time = millis();
while( (time+timeout) > millis())
{
while(esp8266.available())
{
// The esp has data so display its output to the serial window
char c = esp8266.read(); // read the next character.
response+=c;
}
}
if(debug)
{
Serial.print(response);
}
return response;
}
//////////////////////////////////////////////////////////////////////////////////
String webRequest(String url)
{
String response = "";
url = "www.google.es";
//String tmpCommand = "AT+CIPSTART=4," + "\"TCP\",\"" + url + "\",80";
String tmpSTARTCommmand = "AT+CIPSTART=0,\"TCP\",\"retro.hackaday.com\",80\r\n\r\n";
String tmpGETCommand = "GET / HTTP/1.1\r\nHost: ";
tmpGETCommand += "retro.hackaday.com";
tmpGETCommand += ":80\r\n\r\n";
String tmpSENDCommand = "AT+CIPSEND=0," + String(tmpGETCommand.length()) + "\r\n";
sendData(tmpSTARTCommmand, 8000, DEBUG);
sendData(tmpSENDCommand, 8000, DEBUG);
sendData(tmpGETCommand, 15000, DEBUG);
}
This works until the point where I do the webrequest. I receive a Bad request response.
initializing esp8266 port...
.........
FINISH esp8266 initializing!
BâÂúØÐPÊþ^X8Â�Ä^Âú[8ÐûÈâ·CâËØè[8Ð{Èâ·GâÃØRÈ蚉5˜‰0
bÕ
ready
AT+CWMODE?
+CWMODE:3
OK
AV®)AB•«Ë—mX·et","XXX"
OK
AT+CIFSR
+CIFSR:APIP,"192.168.4.1"
+CIFSR:APMAC,"1a:fe:34:9b:c3:83"
+CIFSR:STAIP,"192.168.1.89"
+CIFSR:STAMAC,"18:fe:34:9b:c3:83"
OK
AT+CIPMUX=1
OK
AV%AMEÕÕ*$‘²troÐ…�‘½µ‰,80
0,CONNECT
OK
AVCIPSEND=0,47
> GE#/!QQAŠrŠ%åõÑ: ÊÑɽB�……¹½µÂ‚%\n\r\nbusy s...
SEND OK
+IPD,0,323:HTTP/1.1 400 Bad Request
Server: nginx/1.6.2
Date: Sat, 04 Apr 2015 16:17:29 GMT
Content-Type: text/html
Content-Length: 172
Connection: close
<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx/1.6.2</center>
</body>
</html>
OK
"qXÑzÂC!É1âø‚h[•�™cü ÐQ!}Ñfócú I]Ø÷ÃBj 1¤(ÑÃÖa”K!~CóbÕ
ready
Any idea?
I secceded using this code:
https://github.com/itead/ITEADLIB_Arduino_WeeESP8266/blob/master/ESP8266.cpp
but I have mega2560..
hardware connection:
https://github.com/McOffsky/Arduino_ESP8266_HTTP_Client
Check if it works perfectly, if you use Hardware serial Rx(pin0), Tx(pin1) and Serial monitor, ESP8266 responds properly.
Try lowering baud rate. Most the time SoftwareSerial and
Arduino Uno are not able to handle fast response and loose bit of
information.
If you still receiving the garbage response most likely you module have got damaged.
You shouldn't include port number in get command. Port already specified at cipstart.Something wrong in your http request text. Everything else (sending request and getting response )is ok.
http://en.m.wikipedia.org/wiki/Hypertext_Transfer_Protocol
Check your power supply. I have had these random characters showed up every once in a while when I simply connected the module directly to the Arduino power pins. Those seems like the module is resetting itself constantly and spits out the module info.
My solution was to connect another 3.3v regulator in parallel with Arduino. Connect the grounds together, and supply ESP8266 from that 3.3v power source. Problem solved.

Resources