Hot answers tagged

5

The "Authorization" is simply an HTTP header. So add it in your request like: http.addHeader("Authorization", token); The value of "token" is just the string "Bearer " followed by your authorization string. Don't neglect the SPACE after the word "Bearer". It will look like: "Bearer eyJhb......" ...


5

Your line int httpResponseCode = http.POST("{\"amount\":\"total\"}"); is not doing what you think it's doing. You're not placing the contents of the variable called total in the string, you're placing the word total in the string. Instead you need to build up the string from components before sending. I'd use something like: ...


4

Your incoming string, as Gerben has mentioned, will actually be more like: GET /STA/ID=HelloWorld/Pass=Testin123 HTTP/1.1 My personal preferred method is to use strtok() to split the string up. I'd use a two-pass method for this. First split the string up into three parts - one GET, one the request, and the third the request type (though you don't need ...


4

You mention two different error messages. 1. AT+HTTPINIT fail You get +CME ERROR 3. Which means "operation not allowed". This can be due to an improperly closed HTTP setup. If you get this error (or just always do before setting up), call AT+HTTPTERM to be sure that it's closed. 2. AT+HTTPACTION=1 I notice you're trying to do a POSTmessage, while your ...


4

It looks like you did not send the HTTP headers. Before sending any of the HTML content send following lines: "HTTP/1.1 200 OK\r\n" "Content-Type: text/html\r\n\r\n" Make sure you send all the \r\n !


4

HTTP status code 400 means that your request syntax is invalid. Here's a good way to debug it: store the request in a string, print that, and then transmit it. You'd see very quickly at least one of the problems your code has. String request = String("POST ") + url + "HTTP/1.0 \r\n" + "Host: " + host + "\r\n" + "Accept: *" ...


4

As pointed out by Ignacio Vazquez-Abrams and jsotola, you need to use a state machine, like the one from the Blink Without Delay Arduino tutorial. Yours would be slightly more complicated because you need a way to turn it on and off, and because you use different on and off periods. Here is an example code that abstract the blinking logic into three ...


4

You omitted the protocol part of the url. The HttpClient implementation requires it. Use http.begin("http://www.francescosoave.com/blind/getTime.php"); Do not use Content-type header. You do not send any content. Turn-on debug in Tools menu. Set Debug Port to Serial and Debug Level to HTTP_CLIENT to see the error messages.


4

Try just using IP address for the Host line instead. I did the same thing for POST and it works fine for me. Example: Host: 13.xxx.xx.xx


3

The Adafruit DHT library causes a shortcut on the signal line. That can be a problem for Arduino boards, but it is a big problem for the ESP8266. Issue: DHT init sequence wrong #48 I don't know what is a bigger problem, the shortcut in the code or Adafruit not fixing it. Why do you mention the Arduino Uno with a label ? For the "GET" you should find a good ...


3

The de-facto standard way for devices to broadcast their IP address to clients is through the Multicast DNS system (mDNS). In this system the server sends a UDP message to a specific multicast group address and clients listen for it so they can work out what is where. mDNS is also known as Zeroconf or Bonjour depending on who you talk to. The ESP8266 ...


3

The only way I can think of to achieve this would be to port forward your router, and forward port 80 (http) to your MKR1000. You can check out https://portforward.com/ for instructions on that. If you don't want to port-forward, you'd have to have the MKR1000 connect to a centralized IOT server somewhere, and have the user go through the server to access ...


3

The string "{\"AssetSensorDistance\":\"+st+\"}" contains a literal "+st+". If you want to do string concatenation, you should terminate the string with a double quote character, then add st, then use another double quote to start the second part of the string: "{\"AssetSensorDistance\":\""+st+"\"}"


3

You declare and initialize data as a String in the global space. Then, in loop, you use a bunch of concatenations to build your request string. You never clear the contents of data, but back at the top of loop() on the next round, you concatenate all the string data again, which duplicates it. Side note, the String type is terrible for low-memory devices, ...


3

The getString() method calls writeToStream which is documented write all message body / payload to Stream. It writes all the data of the http response to he output and doesn't store them internally. The next call has nothing to read because the first call to getString() put everything out.


3

there are nice functions inherited from Stream class int parseResponse(char uuid[], int size) { if (!client.find("HTTP/1.1")) // skip HTTP/1.1 return -1; int st = client.parseInt(); // parse status code int l = -1; if (st == 200 && client.find("\"uuid\" : \"")) { int l = client.readBytesUntil('"', uuid, size); uuid[l] = 0; // ...


3

You already received good answer about some general ideas for replacing String objects with C strings. Here I will try to add some more tricks more specifically targeted to your actual situation. I can see two places in your program where the use of String shines by its convenience, and replacing it with C strings will require some effort. The first is the ...


3

Your two best options would be MQTT and WebSockets. Both would open a long lived TCP connection that the ESP8266 and browser could use to transmit and receive data. Both would avoid constant polling to see if there's a new command. MQTT requires an external broker. There are MQTT services with free tiers you could use for this or you could run one locally - ...


3

Yes, there are systems designed to continuously receive such data and the data exchange is standardized, even some Units are standardized. OPC DA An example is OPC Data Access for real time values. It seems you want to build a graph, so OPC Historical Data Access is more what you're looking for. One would set up the data points on the server side once, i.e. ...


3

HTTPS requires that you make an SSL connection not a TCP connection. To do that you need to use AT+CIPSTART="SSL","54.166.71.140 ",443 You also need to configure SSL itself. However the SSL support is not great and struggles with some sites (no SNI support by all accounts). So you're better off programming the ESP8266 directly with ...


3

Try putting your total variable to 0, like this: total = 0; It should work like this.


3

I made it by using EthernetENC library, as suggested by @Juraj. To install the library, simply use the library manager and search for EthernetENC. For those in need, below is a working code #include <SPI.h> #include <EthernetENC.h> byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // ethernet module MAC address IPAddress server(10,10,10,10); ...


2

Slightly off-topic, as this is not the source of your problem, but as jBot42 says, you need a proper regulator. When you use a voltage divider, your load (the ESP8266) is connected in parallel with one of the resistors (the 10K one) and effectively changes the output voltage of the regulator. As the consumption of power in the ESP8266 changes (e.g. when the ...


2

See the text from "'HTTP/1.1 200 OK'" until "'DOCTYPE html'" in the following couple of links which say the same, and you might like to read the rest of those pages: https://www.arduino.cc/en/Tutorial/WebServer http://www.allaboutcircuits.com/projects/using-an-arduino-as-a-web-server


2

From your comment of Jul 1st, I understand that you can program your server in PHP. Then, and to expand on my own comments, I am only recommending that, whatever Web API you design, you keep it as simple as possible. For example, for telling the Arduino whether it should keep the shutter open or closed, you could write something like this in PHP: header('...


2

Hi all use this code below for establishing HTTP connection with the server. And to neglect the 601 or 504 error use proper posting format. Here I'm using JSON format. I just gave manual data. Ignore those errors in HTTPINIT, AT+SAPBR=2,1. The data will be posted to the server #include<SoftwareSerial.h> SoftwareSerial client(2,3); String reading="{ ...


2

You now can try this UPnP_Generic library to do the auto-portforwarding for you without manually touching the router. Many of us are manually port-forwarding in Internet Gateway Device (IGD, Router) in order to provide access to local Web Services from the Internet. This library provides the easier way to automatically port-forward by using the Simple ...


2

I get it now , a stable power source is the answer. arduino with usb can give right amount of Volts but it lacks stable power(amps i guess) while making a TCP connection, that's why module keep restarting.Although it works fine with call, text etc. powering arduino with an AC adapter solves my problem ,now it can connect to mqtt too.Thanks


2

First of all, I would avoid using the String class, because of the memory fragmentation issues that come with it. The most obvious solution is probably to store the result in a character array, then parse the array, with strstr() or sscanf(), to extract the values you want. However, this requires storing the whole response in RAM, which is expensive. A ...


2

Is this project possible without Arduino and just by programming the ESP8266 module? Yes if you use ESP-12 or an esp8266 dev board like Wemos or NodeMCU. The problem could be the current sensor. I would recommend to read it with I2C ADC module, because the esp8266 A0 can read only to 1 V and is shared with WiFi functions. Wemos boards use a circuit to ...


Only top voted, non community-wiki answers of a minimum length are eligible