Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By GengusKahn
#37181 Hi, in this example Twitter is used to display the data but you can also use thingspeak, I have an example of the sketch on the forum, thingspeak can feed into freeboard.io to allow a remote dashboard.

If you look through this and see what it's doing then look through the other references and come back with any questions..........I am using a modified twitter library also posted on the forum...........
Sample Dashboard....
https://freeboard.io/board/5bOyD6
Sample Thingspeak.....
https://thingspeak.com/channels/73184
The Twitter feed from this.....
https://twitter.com/mcuautomation

Code: Select all/* Post a simple message to Twitter  */


#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <Twitter.h>
#include <Wire.h>
#include <SFE_BMP180.h>
SFE_BMP180 pressure;               // i2c Address 77h

#define ALTITUDE 30.0



double baseline;                // BMP180 baseline pressure
double T,P,p0,a;                // BMP180 Data
int TweetInterval= 900;         // Tweet Interval in Seconds
int i=1;                        // How many Tweets
unsigned long ulMeasDelta_ms;   // Time to next Tweet time
unsigned long ulNextMeas_ms;    // next Tweet time
char buf[120];



 
Twitter twitter("You need a Key of your own in here");// Twitter API Key
// Get Yours here http://arduino-tweet.appspot.com/oauth/twitter/login

void setup()
{
  ulMeasDelta_ms = ( (unsigned long) TweetInterval * 1000);  // Tweet Interval in Seconds
  ulNextMeas_ms = millis()+ulMeasDelta_ms;
  if (pressure.begin()){

  }  else
  {
    while(1); // Pause forever.
  }
  WiFi.begin("Your-ssid", "Your-Password");
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
  }
}


void tweet(char msg[]){
  if (twitter.post(msg)) {
    int status = twitter.wait();
    if (status == 200) {
    } else {
    }
  } else {
  }
}


void loop()
{
    if (millis()>=ulNextMeas_ms)
  {   
    ulNextMeas_ms = millis()+ulMeasDelta_ms;
  char status;
  double T,P,p0,a;
  status = pressure.startTemperature();
  if (status != 0)
  {
    // Wait for the measurement to complete:
    delay(status);
    status = pressure.getTemperature(T);
    if (status != 0)
    {
      status = pressure.startPressure(3);
      if (status != 0)
      {
        // Wait for the measurement to complete:
        delay(status);
        status = pressure.getPressure(P,T);
        if (status != 0)
        {
          p0 = pressure.sealevel(P,ALTITUDE); // we're at 1655 meters (Boulder, CO)
          a = pressure.altitude(P,p0);
        }
        else;
      }
      else;
    }
    else;
  }
  else;// ALL OK send tweet
 p0 = pressure.sealevel(P,ALTITUDE);
int TEint = T+0.5;
int MpressU = p0+0.5;
  sprintf(buf, "Current room Temp: %dC Air Pressure(MSLP): %dmbar, %dinHg TweetNo: %d via an #ESP8266", TEint, MpressU, i );
 tweet (buf);
    i++;
  }
}

User avatar
By SoC
#37193 genguskhan,
ryanc is asking info regarding controlling esp8266 over the internet.
not esp8266 sending data to internet like your two examples.
btw, you dont need port forwarding when you just want to send data to thingspeak, or twitter.
User avatar
By bateau62
#37243 @RyanC:

What you are planning to do is indeed a fairly common thing: Many people want to be able to control a device from over the internet. The reason why there are no simple (noob-friendly) solutions to this is because the simple solutions very likely will get you into trouble, either from a maintenance point of view, either from a security point of view (or both).

Before going further, you need to take into account:
* Do you want this secured? I do not know what you are planning to use this for, but if this is for example for your home alarm or your heating, I advise to set up some security.
* Who is going to control this? Only you or many others? This has a big impact on the security needed.
* Do you plan on installing this in a single, well controlled environment, or do you plan to install this in many different places? What effort are you willing to put in the installations in each of those sites?
* Can you control the firewall and WAN router on the sites where you plan to install this?
* Do you plan on updating the application often? Maintenance can be very hard.
* Do you really want something homemade? Are you willing to adapt your solution to leverage existing platforms? There are plenty IoT platforms out there that can help you with this type of use.
* What type of user interface do you want on it? Simple URL or some visually pleasing fancy controls? The fancier you want, the harder it is to make.

This is just a very short list of questions that can help determine the best solutions.

You must also understand that connecting to the internet is not very simple. Anyone can pick up a browser, contact a web server, and get a reply from that server. That is because your router is geared toward letting outgoing requests pass through, and let replies to those requests come back in.
For a whole series of reason, security being one of them, your router does not simply let unrequested internet traffic coming in to your house and contact any device in your home.

Either you tell your router it is OK to let people from the outside talk to one of your devices (solution 1 I propose below), either your device has to talk to a third party, and you talk with your device through that third party (solution 2 I propose below). (either you use P2P hole punching techniques, but that is very complicated to set up)

Let me give you 2 potential solutions, based on some extreme use cases:
1)
IF: you are the only one using it, in your house, you do not move it to other sites, you do not want to control sensitive or dangerous or costly devices, you accept that there are hackers getting in from time to time, you do not care about a rather unfriendly user interface.
THEN:
* set up the device on your LAN with a web server, maybe add a password to the service. There are are some examples on the esp8266 arduino github for that. You used one.
* set up a DMZ on your WAN (ADSL/Fibre/Cable) Router or set up something called "port forwarding" on that router. This is pure configuration on that router, nothing to do with your code, and strongly depending on your ISP and your router. Talk your ISP for that, we cannot help you there, too many different ISPs and boxes out there.
* set up a DDNS service (like dyndns or no-ip or others) in your router (if the router supports it). If your router does not support it, either request a fixed IP address from your ISP (talk to them), or set up an DDNS agent on one of your PCs/devices inside the LAN, or simply accept that your public IP address changes from time to time.
* Note that some ISPs simply do not allow this setup. Talk to them in that case or switch ISPs.
* Talk to your device through the public IP address, NOT through the local IP address. (hint: 192.168.x.x and 10.x.x.x are local addresses, you CANNOT reach them from the internet)

2)
IF: potentially many people are using it, you want some security on it, you do not want a big hassle when installing or moving to other sites, you want a nice user interface, you are willing to have a user interface that does not have your name written all over.
THEN:
* look for an IoT (Internet Of Things) platform that looks like it can deliver the type of service you want. There are easily hundreds out there that to me look like they can. (disclaimer: I work for one, sorry, high volume B2B only). You will probably want one that is already integrated on ESP8266. This thread mentions some. Look above.
* adapt your code to make it talk to the platform you chose.
* use that platform
User avatar
By GengusKahn
#37253 Hi there SOC, if you look properly you will have seen me inform in the post that for the posting of data port forwarding is not needed, but for interaction you walk before you run, the data goes to widget on thingspeak and via callback the ESP8266 "reacts" without the need to "Expose" the ESP through Port Forwarding, but equally simple is ...
ESP "exposed" to the internet via port forwarding...

Feel free to look around, there are scripts for various visualisations and lots of pictures......

http://82.5.78.180:82/edit