These are chat archives for esp8266/Arduino

26th
Apr 2017
Steve Nelson
@zenmanenergy
Apr 26 2017 00:43
Can someone tell me if I'm doing this syntax right? It's not throwing errors, but the syntax doesn't make sense to me:
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>

class GameServer
{
  public:
    GameServer();

  private:
    AsyncWebServer _server(...);
};

GameServer::GameServer(){
   AsyncWebServer _server(80);
}
I'm confused by the ... syntax. Do I not have to specify the arguments in the class?
CodingCreature
@CodingCreate101
Apr 26 2017 03:35
@rodrigocirilo well, you do have option in android to act as server and your esp as client. However, if you want to access it from computer itself, do you have any specific app to do that? there are applications, like, putty. Or you can even use your browser. To do that, there are actually examples given in the library you have downloaded. Refer those.
rodrigocirilo
@rodrigocirilo
Apr 26 2017 12:38
I do not want esp working as webserver but rather as client connected to a VC # application and both with the possibility of exchanging data between each other
Steve Nelson
@zenmanenergy
Apr 26 2017 12:42
Nikolas Beutler
@biacz
Apr 26 2017 12:43
if you once solder your esp01 into a pcb. how are you supposed to program it afterwards? i dont think you are, right? :D
Steve Nelson
@zenmanenergy
Apr 26 2017 12:43
That will setup the node as a websocket server which works a little different from a webserver. Then the smartphone/desktop can connect to the node and maintain the connection to the node
@biacz you still can. the esp01 has rx/tx pins, so you just connect those to an ftdi and you can upload a sketch. Also if you setup OTA (over the air) before you solder it you can update it remotely without the rx/tx
another way to do it is to solder header pins onto your project and just pull the esp01 out and use another device to program it
that way your project doesn't have to expose the rx/tx pins.
Nikolas Beutler
@biacz
Apr 26 2017 13:01
OTA works on 512k? depends on my sketch though, right?
@zenmanenergy also, the tx pin is actually soldered to a pullup resistor and used in the sketch. would that still work?
Steve Nelson
@zenmanenergy
Apr 26 2017 13:04
@biacz usually not on 512k, but the black esp01s are 1024k. As long as you keep the sketch relatively small (i.e. less than half than the total space), I've done remote updates on those.
oh... hmmm, probably not. you mean you have a gps or something like that on it?
Nikolas Beutler
@biacz
Apr 26 2017 13:04
nah its running a LED strip and therefor i have to use all 3 pins
but thanks, ill make sure to use OTA next time. i am actually using it for all my nodemcus but i think my sketch is too big
Steve Nelson
@zenmanenergy
Apr 26 2017 13:07
I don't think it will if the LED is connected, but I've never tried. I know on my nodemcu if i have a GPS plugged into the rx pins, i can't upload through usb. but maybe a gps is different from an LED. maybe one of the guys here that is smarter about EE would know the answer.
Nikolas Beutler
@biacz
Apr 26 2017 13:24
oh well
@zenmanenergy i am pretty sure if i boot it with gpio0 on low, it definitely lets me flash it. thats only one pin to care about ;-)
Steve Nelson
@zenmanenergy
Apr 26 2017 13:27
well yes, but you still have to do that to transfer the data. But if the rx pin is connected to another device the arduino ide gets angry.
you won't like it when it's angry.
Nikolas Beutler
@biacz
Apr 26 2017 13:29
ill give it a try
hope OTA works as i am designing real pcbs now and ask a company to print them
once i got my esp soldered into those, i hardly wont get anything changed on it again
Steve Nelson
@zenmanenergy
Apr 26 2017 13:31
good luck!
rodrigocirilo
@rodrigocirilo
Apr 26 2017 13:39
@zenmanenergy

@zenmanenergy Thanks for the link .. but I'm lost.

Let me explain what I would like to do:

NodeMcu (ESP) would be the client (I will have more than one, connected to the server) and the desktop will be the server.

(Let's forget for now the VC #, we will use a terminal TCP / IP Server (hercules for example).

Currently I can send a string to the server, but I can not send a message from the server to the client (nodemcu).

I need to establish some form of communication of TWO WAYS.

CodingCreature
@CodingCreate101
Apr 26 2017 13:42
@rodrigocirilo the video link that I sent has server example but if you go to their channel they have explained other examples too. However they don't have exactly what you just explained. So, currently which service of TCP you are using to send command from client to server?
rodrigocirilo
@rodrigocirilo
Apr 26 2017 13:43
@zenmanenergy my code

include <ESP8266WiFi.h>

const char ssid = "storeone";
const char
password = "onestore";
const char* host = "192.168.1.106";

define INP1 14

define LED 2

String line;
void setup()
{
Serial.begin(9600); // Inicia comunicação Serial em 9600 baud rate

pinMode(INP1, INPUT_PULLUP);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while(WiFi.status() != WL_CONNECTED)
delay(500);

 Serial.println("test");

}

void loop()
{

WiFiClient client;
if(digitalRead(INP1)==0)
{
if(!client.connect(host, 80))
return;

  client.print("INP ACTIVE");
   delay(250);

}

  while(client.available())  //HERE DONT RECEIVED ????
    line = client.readStringUntil('\r');      

}

@CodingCreate101 @CodingCreate101 See my code please
CodingCreature
@CodingCreate101
Apr 26 2017 13:46
You are using http right now
Steve Nelson
@zenmanenergy
Apr 26 2017 13:48
I haven't played with tcp/ip directly, I usually am either connecting through a webserver or a websockets server. have you looked at the telnetclient.ino?
rodrigocirilo
@rodrigocirilo
Apr 26 2017 13:48
@CodingCreate101 I think not, actually I do not want to use http, nor get nor post
CodingCreature
@CodingCreate101
Apr 26 2017 13:48
For simplicity why don't you use telnet first, using 23rd port?
Port 80 that you are using is http
rodrigocirilo
@rodrigocirilo
Apr 26 2017 13:49
@zenmanenergy @zenmanenergy I do not understand much, I'm starting, I think websocket would be good to use
@CodingCreate101 @CodingCreate101 Sorry for that port, I used this without knowing it was http, could open any port on my router and use it
CodingCreature
@CodingCreate101
Apr 26 2017 13:50
Use 23. It's telnet
Steve Nelson
@zenmanenergy
Apr 26 2017 13:51
the advantage with websockets is it allows two way communication through a firewall. I've had good luck using node.js on the server side. markus has some example websocket client code in his repository: https://github.com/Links2004/arduinoWebSockets
rodrigocirilo
@rodrigocirilo
Apr 26 2017 13:51
@CodingCreate101 @CodingCreate101 But with telnet communication I could communicate in two ways?
CodingCreature
@CodingCreate101
Apr 26 2017 13:51
Yes
It's two way communication.
rodrigocirilo
@rodrigocirilo
Apr 26 2017 13:52
@CodingCreate101 @CodingCreate101 Would you have some example of this for nodemcu arduino IDE
CodingCreature
@CodingCreate101
Apr 26 2017 13:52
Just a minute, I ll send you an example. i am on mobile- shifting to laptop
rodrigocirilo
@rodrigocirilo
Apr 26 2017 13:53
@zenmanenergy @zenmanenergy Yes, websockets looks good, as it creates a direct tunnel between the devices, thanks for the link, I'll take a look and try to understand
@CodingCreate101 thank you so much
Steve Nelson
@zenmanenergy
Apr 26 2017 13:53
@CodingCreate101 I'd love to see that too.
rodrigocirilo
@rodrigocirilo
Apr 26 2017 13:55
@CodingCreate101 Through telnet will the server accept multiple connections from multiple clients at the same time?
@zenmanenergy There is difference in websockets and tcp / ip sockets
Steve Nelson
@zenmanenergy
Apr 26 2017 13:58
I would assume so. I've just never gone down the path of doing tcp/ip directly. I assume it would involve a considerable amount of parsing the data packets.
rodrigocirilo
@rodrigocirilo
Apr 26 2017 13:59
What do you guys tell me about the code I posted?
Steve Nelson
@zenmanenergy
Apr 26 2017 14:01
Did you try swapping 80 for 23 like @CodingCreate101 suggested? 23 is telnet, 80 is http.
CodingCreature
@CodingCreate101
Apr 26 2017 14:12
Alright, try this code. This should work out pretty well for you. If not, let me know. :)
#include <ESP8266WiFi.h>
  #define       LED0      2         // WIFI Module LED
//------------------------------------------------------------------------------------
String Message="";
//------------------------------------------------------------------------------------
// Authentication Variables
//------------------------------------------------------------------------------------
  char*         connect_to = "ssid";
  char*         pass = "password";
  IPAddress     qwertyServer(192,168,4,1);
  WiFiClient    qwertyClient;
//====================================================================================

  void setup()
  {        
    // Setting The Mode Of Pins ---------------------------------------------
    pinMode(LED0, OUTPUT);          // WIFI OnBoard LED Light
    digitalWrite(LED0, !LOW);       // Turn WiFi LED Off

    // Print Message Of I/O Setting Progress --------------------------------
    //Serial.println("\nI/O Pins Modes Set .... Done");

    // Starting To Connect --------------------------------------------------
    WiFi.mode(WIFI_STA);            // To Avoid Broadcasting An SSID
    WiFi.begin(connect_to, pass);          // The SSID That We Want To Connect To

    // Printing Message For User That Connetion Is On Process ---------------
    Serial.println("!--- Connecting To " + WiFi.SSID() + " ---!");

     // Setting The Serial Port ----------------------------------------------
    Serial.begin(9600);           // Computer Communication
    delay(500);
    Serial.print("\n");

    // WiFi Connectivity ----------------------------------------------------
    CheckConnectivity();            // Checking For Connection  
  }

//====================================================================================

  void loop()
  {

    if(WiFi.status() != WL_CONNECTED)
    {
        Serial.println("\nOops! Connection lost. Trying to reconnect " + String(WiFi.SSID()));
        Serial.println("");
        CheckConnectivity();
    }
    else if(qwertyClient.available() > 0)
    {
        ReadMessage();
        Serial.print(Message);

      qwertyClient.flush();
      }

  }
//====================================================================================

  void ReadMessage()
  {
      Message = "";
      Message = qwertyClient.readStringUntil('\r');
  }

//====================================================================================

  void CheckConnectivity()
  {
    while(WiFi.status() != WL_CONNECTED)
    {
      for(int i=0; i < 2; i++)
      {
        digitalWrite(LED0, !HIGH);
        delay(50);
        digitalWrite(LED0, !LOW);
        delay(550);
        Serial.print(".");
      }
      Serial.println("");
    }

  // Stop Blinking To Indicate Connected ----------------------------------
    digitalWrite(LED0, LOW);
    Serial.println("\n!-- Client Device Connected --!");
    Serial.print("\n\n");

    // Printing IP Address --------------------------------------------------
    Serial.println("Connected To      : " + String(WiFi.SSID()));
    Serial.println("Signal Strenght   : " + String(WiFi.RSSI()) + " dBm");
    Serial.print  ("Server IP Address : ");
    Serial.println(qwertyServer);
    Serial.print  ("Device IP Address : ");
    Serial.println(WiFi.localIP());

    // Conecting The Device As A Client -------------------------------------
    ClientRequest();

  }

//====================================================================================

  void ClientRequest()
  {
    // First Make Sure You Got Disconnected
    qwertyClient.stop();

    // If Sucessfully Connected Send Connection Message
    if(qwertyClient.connect(qwertyServer, 23))
    {
      delay(250);
      Serial.print("status\n");
      Serial.println    ("Connected");
      qwertyClient.println ("Connected");
    }
  }
rodrigocirilo
@rodrigocirilo
Apr 26 2017 14:12
i need to leave right away, i'll back
CodingCreature
@CodingCreate101
Apr 26 2017 14:12
Np
Steve Nelson
@zenmanenergy
Apr 26 2017 14:15
thanks @CodingCreate101. btw, what does flush() do?
CodingCreature
@CodingCreate101
Apr 26 2017 14:18
It clears buffer.. So that it wouldn't interfere with any other data it might have in the near future - while sending or receiving.
Steve Nelson
@zenmanenergy
Apr 26 2017 14:22
Is that just a memory saving issue? would qwertyClient.readStringUntil('\r') just overwrite the buffer when new data comes in?
CodingCreature
@CodingCreate101
Apr 26 2017 14:28
I don't think it does. Well, it does but not entirely. It actually interferes with 'remaining' data. For example, if previous data is "123456" and current data is "abcd", in buffer, you would find "abcd56" It's not memory saving issue. It's actually a big issue where continuous communication is necessary. I had lot of troubles when I didn't use flush() at right places.
Steve Nelson
@zenmanenergy
Apr 26 2017 14:29
ohhhh I see.
I've spent so many years working in scripting languages where people far smarter than I am dealt with issues like that!
CodingCreature
@CodingCreate101
Apr 26 2017 14:32
Hahha. Yeah, those are sneaky traps.
rodrigocirilo
@rodrigocirilo
Apr 26 2017 14:40

I'm by smaetphone so it's bad to read / write.

Well I found this code interesting, but where is the part of sending data to the server?

Could I replace port 23 with some other one I open on my router for server ip?

CodingCreature
@CodingCreate101
Apr 26 2017 14:42
I think you can but you have to follow it's protocol.
rodrigocirilo
@rodrigocirilo
Apr 26 2017 14:42
I'm going to test this code soon enough.
CodingCreature
@CodingCreate101
Apr 26 2017 14:42
Sending code to server is last line
qwertyClient.print("something");
print with ln is just for newline
rodrigocirilo
@rodrigocirilo
Apr 26 2017 14:46

Okay, now I understand, I'll test when I get back to the laptop.

About port 23 could use another? That was open for server ip?

Thank you so much for now.

CodingCreature
@CodingCreate101
Apr 26 2017 14:47
Yeah, IP doesn't matter until you are in same network.
rodrigocirilo
@rodrigocirilo
Apr 26 2017 14:50
I'm talking about port 23, can I use another one?
CodingCreature
@CodingCreate101
Apr 26 2017 15:11
You can. But you have to use whatever protocol that port supports. Depending on ports, they have their own protocols.
23 is for telnet and it's probably the simplest one.
rodrigocirilo
@rodrigocirilo
Apr 26 2017 15:18
ok, I got it
If not ask too much, you would have an example of the code for vidual studio c # to communicate with this example
Steve Nelson
@zenmanenergy
Apr 26 2017 15:31
@CodingCreate101 do you happen to be intimately familiar with ArduinoJson?
actually I guess this is more of a general pointer question. Is anyone here a master of pointers? The syntax still baffles the hell out of me.
Martin Ayotte
@martinayotte
Apr 26 2017 15:39
Json syntax are key/value scheme like : { "key1": "value1", "key2": "value2" } , where here all values are strings, but it could be integers or boolean.
Steve Nelson
@zenmanenergy
Apr 26 2017 15:40
my question is really more of a pointer issue.
Martin Ayotte
@martinayotte
Apr 26 2017 15:40
Json could not handle pointers, since they are irrelevant for communication.
Steve Nelson
@zenmanenergy
Apr 26 2017 15:40
one sec... trying to organize my question.
I'm trying to make a .h file that reads a json file from the FS, parses it, then stores the parsed object into a private variable in the class.
It doesn't seem to like it if i use do:
private:
    JsonObject& _players;
it doesn't throw an error if I do this:
private:
    JsonObject * _players;

but then inside one of the methods I throws an error when I do this:

StaticJsonBuffer<200> _jsonBuffer;
      _players = _jsonBuffer.parseObject(playersJson);

cannot convert 'ArduinoJson::JsonObject' to 'ArduinoJson::JsonObject' in assignment
_players = _jsonBuffer.parseObject(playersJson);
^
exit status 1
cannot convert 'ArduinoJson::JsonObject' to 'ArduinoJson::JsonObject
' in assignment

any idea what I'm doing wrong?
Martin Ayotte
@martinayotte
Apr 26 2017 15:47
What error are you getting with the "JsonObject & _players" version ?
Steve Nelson
@zenmanenergy
Apr 26 2017 15:48
it's really weird. it's like it's a syntax error, it throws the error on the constructor...
ketch/players.h: In constructor 'Players::Players()':
players.h:26: error: uninitialized reference member 'Players::_players' [-fpermissive]
Players::Players(){
^
exit status 1
uninitialized reference member 'Players::_players' [-fpermissive]
Martin Ayotte
@martinayotte
Apr 26 2017 15:49
I don't know ! I will have to dig and try myself to figure out.
Steve Nelson
@zenmanenergy
Apr 26 2017 15:50
hmmm. I wonder if i have to setup a member variable or something. this c++ stuff makes my brain hurt!
it's the "uninitialized reference member 'Players::_players'" error that confuses me. wtf is that?
i gotta step out for a bit. Martin if you figure anything out, I'd love to hear your thoughts.
rodrigocirilo
@rodrigocirilo
Apr 26 2017 15:53
@CodingCreate101 What software do you use to test the communication of this code?
Steve Nelson
@zenmanenergy
Apr 26 2017 16:22
@martinayotte my temporary solution is to store the char *playersJson as a private variable. But that means every method has to parse it again which is pretty lame.
Martin Ayotte
@martinayotte
Apr 26 2017 17:03
@zenman"energy , I found the trick, use pointer "JsonObject * _players;" and in the constructor, do "JsonObject &obj = jsonBuffer.parseObject(json_string);" followed by " _players = &obj;"
Then in functions, make sure to use "_players->functions()"
Steve Nelson
@zenmanenergy
Apr 26 2017 17:10
sweet. I'll try that.
Martin Ayotte
@martinayotte
Apr 26 2017 18:54
@zenmanenergy , I've tested more MyJsonClass , and it getting corrupt after some operations, you need to have the DynamicJsonBuffer also member of the class.
Also, I found problem if the MyJsonClass in instantiated on the stack, and moving it as global object fix the issue.
Steve Nelson
@zenmanenergy
Apr 26 2017 19:00
you got it to crash with the staticbuffer?
Martin Ayotte
@martinayotte
Apr 26 2017 19:05
Maybe try the DynamicJsonBuffer...
Steve Nelson
@zenmanenergy
Apr 26 2017 19:05
Check this out...
 private:
    DynamicJsonBuffer _jsonBuffer;
    JsonVariant _jsonVariant;
    const JsonObject& root() const { 
      return _jsonVariant;
    }
then inside the methods you call it like this:
_jsonVariant = _jsonBuffer.parseObject(jsonString);
      if (root().success()){

        Serial.println("success!");
      }else{
        Serial.println("nope");
      }
i just tried that on a pretty simple packet and it worked.
I'm not certain if there is a big advantage or no advantage to doing it like this versus a global variable.
CodingCreature
@CodingCreate101
Apr 26 2017 19:19
@rodrigocirilo Serial monitor of arduino IDE is good enough, also, of course, something to receive on the other side as server. I used socket protocol and when things got complected, I had to build my own app. On computers, 'putty' might work well for you now. And then build your dedicated app using C#. I am sure you will find lot of resources for that online.
'
brutzler
@brutzler
Apr 26 2017 19:50
Hi,
has anybody seen a project with an ESP as standalone serial-wifi bridge?
Thinking about connecting an ESP-12 with the RX/TX to an ESP8266 (TX/RX).
And the ESP-12 connects to the router and sends all serial debug-signals from the ESP8266 over telnet to a connected computer with a telnet-client.
rodrigocirilo
@rodrigocirilo
Apr 26 2017 19:58
@CodingCreate101 I tested your code, but nothing happens ??
Bert Melis
@bertmelis
Apr 26 2017 20:13
@brutzler I don't understand what you're trying to achieve. Can't you program the ESP8266 to send them directly to your telnet client?
Otherwiss, have you actually explored the Arduino/ESP8266 examples? There's a WiFiTelnetToSerial example that does just what you want.
rodrigocirilo
@rodrigocirilo
Apr 26 2017 20:19
@CodingCreate101 tive que copiar essa parte e colar no loop infinito
if(qwertyClient.connect(qwertyServer, 23))
{
delay(250);
Serial.print("status\n");
Serial.println ("Connected");
qwertyClient.println ("beleza");
}
@CodingCreate101 sorry for portuguese hehe
I had to copy that part and paste it into the infinite loop
if(qwertyClient.connect(qwertyServer, 23))
{
delay(250);
Serial.print("status\n");
Serial.println ("Connected");
qwertyClient.println ("beleza");
}
@CodingCreate101 There began to traffic data in both directions
brutzler
@brutzler
Apr 26 2017 20:52
@bertmelis
Yes, you are right. I could program the ESP to make this directly. But I already have OTA, Webserver, Ntp and a TCP-client running on the ESP. And I do not need the debug all the time.
My intention is the following: If I have my ESP8266 in the near of my computer, I connect a FTDI USB-serial to the ESP-debug interface (serial1). If the ESP is on a different place, I just connect the ESP-12 to the debug-interface, and get the debug messages to my telnet-client over WiFi. Without any change in the code...
I will check out the example :-) thx
CodingCreature
@CodingCreate101
Apr 26 2017 21:10
Interesting. But I am still not convinced why you would need an extra-ESP in serial with main one? Is it to reduce pressure on main-ESP?
Anyhow, let us know how it goes. I would want to make this arrangement too. Makes my life lil'easy.
@rodrigocirilo so I think it's going well :)
@rodrigocirilo I know only one word in Portuguese: Epico
:P
brutzler
@brutzler
Apr 26 2017 21:55
@CodingCreate101 ok. will keep you informed