Chat freely about anything...

User avatar
By Backbone
#29146 Hi, I am new to the ESP8266 and need some general confirmation if it is possible to do a project.
I have a ESP8266-201 ready on the breadboard and I can add code to it.... :-)
I need to view the data from four force sensors which will take 8 GIOP's and send 9 pieces of seperate data to an application or webpage in a 3 x 3 matrix directly from the SP8266 to a mobile phone. This instead of adding a display to the project the mobile Phone is used as interface/display
From the mobile Phone I need to control the ESP8266 with five buttons (or more) to control left, right, up, down and reset.
There is no need for high speed, a refresh rate of 1 second is no problem.
I need to know if a mobile Phone user can connect directly to the ESP8266 by WiFi without using a router or other network.
More like ADHOC connection as that is the correct way of saying?
No need for internet connection to show or share the data.
Data will be placed by Arduino IDE directly into the ESP8266.

Thanks for any suggestion.

Paco
User avatar
By eduperez
#29172 So, you basically want to have a ESP acting as an Access Point and serve a web page; than page will reflect the inputs on the ESP8266, and have some buttons to change the outputs on the ESP8266. Right?

As long as you have enough GPIOs on the ESP, or can do with a GPIO expander, the rest seems quite doable to me.
User avatar
By Backbone
#29177 Thanks for the answer.
Yes that is what I like to achieve.

For my understanding.
Route to go in blocks.........
So one time send code to ESP8266
Arduino Code has:
1] Send command to set ESP as Access Point
2] SSID sending out is "WeigthScale"
3] Password is "123456789"
4] Code to show data on HTML page (.post)
5] Code to read button actions on HTML page (.get)
6] Fixed IP address like 192.168.9.1

On mobile Phone first pair with the ESP accesspoint and connect with SSID and Password.
Then browse to 192.168.9.1 so the page opens and is active.

Is my understanding correct?

Thanks, Paco
Last edited by Backbone on Wed Sep 16, 2015 11:26 am, edited 1 time in total.
User avatar
By eduperez
#29179 Yes, I think that sums it up!

For your reference, this is the code that I am currently using for a similar project; I set my ESP as a client, and have to deal with just one input and one output, but I think it can be a good starting point:

Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

const int PIN_INPUT  = 2;
const int PIN_OUTPUT = 0;

const char* ssid     = "my_ssid";
const char* password = "my_password";

int input_prev;
int input_curr;
int output;

ESP8266WebServer server(80);

void do_on() {
  Serial.println("OUTPUT: on");
  digitalWrite(PIN_OUTPUT, HIGH);
  output = HIGH;
}

void do_off() {
  Serial.println("OUTPUT: off");
  digitalWrite(PIN_OUTPUT, LOW);
  output = LOW;
}

void do_get() {
  if (output)
    server.send(200, "text/plain", "ON");
  else
    server.send(200, "text/plain", "OFF");
}

void handle_root() {
  Serial.println("HTTP  : root");
  server.send(200, "text/plain", "Hello from the ESP8266!");
}
 
void handle_on() {
  Serial.println("HTTP  : on");
  do_on();
  do_get();
}
 
void handle_off() {
  Serial.println("HTTP  : off");
  do_off();
  do_get();
}
 
void handle_get() {
  Serial.println("HTTP  : get");
  do_get();
}

void setup(void)
{
  Serial.begin(115200);
  Serial.println("\n\rStarting...");

  pinMode(PIN_OUTPUT, OUTPUT);
  pinMode(PIN_INPUT, INPUT);
 
  input_prev = digitalRead(PIN_INPUT);
 
  Serial.print("Current status: ");
  Serial.println(input_prev);

  if (input_prev) {
    do_on();
  } else {
    do_off();
  }

  server.on("/",    handle_root);
  server.on("/on",  handle_on);
  server.on("/off", handle_off);
  server.on("/get", handle_get);

  server.begin();
  Serial.println("HTTP server started");
}
 
void loop(void)
{
  if(WiFi.status() != WL_CONNECTED) {
    Serial.print("Trying to connect");
    WiFi.begin(ssid, password);

    for (int i = 0; i < 10 && WiFi.status() != WL_CONNECTED; i++) {
      delay(500);
      Serial.print(".");
    }

    Serial.print("\n\r");
   
    if(WiFi.status() == WL_CONNECTED) {
     
      Serial.print("Connected to  : ");
      Serial.println(ssid);
     
      Serial.print("IP address    : ");
      Serial.println(WiFi.localIP());
    }
  }

  if(WiFi.status() == WL_CONNECTED) {
    server.handleClient();
  }
 
  input_curr = digitalRead(PIN_INPUT);

  if (input_curr != input_prev) {
    if (input_curr) {
      Serial.println("INPUT : on");
      do_on();
    } else {
      Serial.println("INPUT : off");
      do_off();
    }

    input_prev = input_curr;
  }

  delay(250);
}