Wemos D1 mini - Vodafone New Zealand 4G | ESP8266 Wi-Fi Module | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Wemos D1 mini - Vodafone New Zealand 4G
No permission to create posts
August 11, 2017
4:56 am
Avatar
SteveMcC
New Member
Members
Forum Posts: 2
Member Since:
August 1, 2017
sp_UserOfflineSmall Offline

Hello All

I thought it would be of some help to this community to share my experiences with getting a thingspeak device working here in New Zealand.

I am using a wemos D1 mini to upload my temperature data to thingspeak for a year or so before it “stopped” working.  My original project used LUA and worked fine.

I thought the problem was that the code had become corrupted (I found a few people who mentioned the same problems as I was having) so I set about converting the LUA code to Arduino.

I could not for the life of me get any of the example code on the web working at all.  I could connect to the wifi no problem; it would allocate my wemos an IP address.  When the code ran I could even see the IP address of the thingspeak servers, and it connected to them fine.

The problem was when the code got to the following line, it would time out and fail.

client.print("POST /update HTTP/1.1
");

I took the device to work(a fibre connection to the internet), and the code work perfectly, but I could not get it to work at my home, or even through a wifi hotspot from my cellphone.

I discovered that the problem was with my internet connection at my home.  My internet connection is through Vodafone using their wireless broadband 4G network.  It appears that Vodafone (I won’t say blocks) but doesn’t allow the particular ports used by the WiFiClient connection through.

I changed my code so that it uses the HTTP client instead.  This worked well, and I have been successfully using this for a few months now.

Relevant Snippets of the code I used is below.

I am sending two strings of information to thing speak.  The temperature outside my house, and the voltage of my batteries, thus the two values being passed to the function.

 

#include <ESP8266HTTPClient.h>  // instead of #include <ESP8266WiFi.h>

..

..

..

void PostToThingSpeak(float celsius, float voltage){

String updateURL = "http://";

updateURL += String(server);

updateURL +="/update?api_key=";

updateURL += String(apiKey);

updateURL +="&field1=";

updateURL += String(celsius);

updateURL +="&field2=";

updateURL += String(voltage);

client.begin(updateURL);

int httpCode = client.GET();  // I guess I could check that I get a “1” as confirmation but I implemented that yet

client.end();

}

 

For those of us who like a  “TLDR” Summary:

Could not connect using normal "client" code through vodafones network here in new Zealand, so had to adjust the code to use the httpclient method.

August 12, 2017
7:51 am
Avatar
rw950431

Top
Members
Forum Posts: 269
Member Since:
January 30, 2014
sp_UserOfflineSmall Offline

For the record what port was your original code connecting to?

August 14, 2017
10:24 pm
Avatar
SteveMcC
New Member
Members
Forum Posts: 2
Member Since:
August 1, 2017
sp_UserOfflineSmall Offline

I was connecting using port 80...

for example the code below was one of the examples I tried to use.....and I could not get it to work....

(I have since then spoken to a friend who works in IT, and apparently there are different APN's that can be used with vodafone NZ network, and some of them allow different ports access through their firewalls, but I am not sure I can confirm or deny this)

if (client.connect(server,80)) {
String postStr = apiKey;
postStr +="&field1=";
postStr += String(t);
postStr +="&field2=";
postStr += String(h);
postStr += "



";
 
client.print("POST /update HTTP/1.1
");
client.print("Host: api.thingspeak.com
");
client.print("Connection: close
");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"
");
client.print("Content-Type: application/x-www-form-urlencoded
");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("

");
client.print(postStr);
 
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" degrees Celsius Humidity: ");
Serial.print(h);
Serial.println("Sending data to Thingspeak");
}
Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
17 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

dollyip18, toddbt2, SatrapB, Ronalpsync, wandaim69, GregoryGof

Administrators: Hans: 387, lee: 457