Cannot Receive/Send multiple messages using Arduino WIFI library on two ESP8266s (Client/Server)

I’m trying to get two or more ESP8266s (NodeMCU) to communicate with each other using the below code in a client / server format using the Arduino WIFI library.
Essentially, what I want is something like the below conversation:

client: Server are you there?

server: I’m here

server: Send me Temp Reading

client: Temp reading – 72 degree F

server: do something

client: done

I’ve been able to read the first line printed to the server from the client, but the second line doesn’t come through. The line printed or written by the server to the client doesn’t seem to work either. I’m certain it is either something I don’t understand about how wifi comm works or something about the code functions that I’m not grasping.

I’m only posting the void loop code, as the remainder of the code works just fine. I’ve tried modifying the code in dozens of different setups (adding delays in different locations, flushing, stopping and reconnecting, etc.) based on research on the topic, but I’m missing something.

CLIENT SIDE

void loop () {
  digitalWrite(ledPin,LOW);
  client.connect(server, 80);   // Connection to the server
  Serial.println(".");

//to server
  client.println("1r");  // sends the message to the server

//from server
  String answer = client.readStringUntil('r');

//to server
  client.flush();
  delay(5000);
  client.println("2r");
  digitalWrite(ledPin, HIGH);
  delay(2000);                  // client will trigger the communication after two seconds


}

SERVER SIDE

void loop () {
  WiFiClient client = server.available();

  if (client){
    while (client.connected()) {
      if (client.available()>0){
      digitalWrite(ledPin, HIGH);  // to show the communication only (inverted logic)
      Serial.println(".");

      //to server
      String request = client.readStringUntil('r');    // receives the message from the client
      Serial.println(request);

      //................................................
      if (request == "1") {
          Serial.print("Client Sending Temp: Acknowledged"); Serial.println(request);        
      } else {
          Serial.print("Client Sending Temp: Failed"); Serial.println(request);
      }
      server.write("Send Temp Reading");
      //................................................
      if (request == "2") {        
          Serial.print("From client 2.2: "); Serial.println(request);
          digitalWrite(ledPin, HIGH);
      } else {
          Serial.print("From client 2.1: "); Serial.println(request);
      }

      //................................................
      client.flush();
      client.stop();                // terminates the connection with the client
      }
    }
  }
}

In the serial monitor all I get back is:

.

1

Client Sending Temp: Acknowledged1 (this is reading the first line from the client)

From client 2.1: 1 (this is acknowledging that the second line isn’t reading).

This just repeats over and over again. So, I know the connection is working based on the first read, but what I’m not understanding is why I can’t get the second line from the client or why I can’t receive (on the client’s side) what the server prints or writes to it.

All topic

C – `0` special character appear using malloc

I’m having some trouble using malloc during a concatenation. It seem when I malloc my pointer, a character is automatically added. This append after many loop who already worked, I use malloc on a null pointer set up 2 line before, I’m using only number for which exist, cur_len, sub_len.

It seem to be a normal thinks, but at a moment this special character automatically pop up. Actually, it seem (for me) displayed as a single character when it’s printed (see picture 2), but when I check the new_str value through lldb, '0' (with blockquote) is in three character…

lldb representation
When the caracter is printed :
enter image description here

If anyone can give me a clue, it tried some stuff, not able to understand for the moment. Thanks to you, I hope I was clear.

All topic

Setting up a double opt-in without using any Subscriber List features (publication list, etc.) and just data extension – possible?

Is there a way to set up a double opt-in without the usage of Subscriber List/Publication List?

Instead of the method of linking the Data Extension to the publication list, is there a way to directly manage the subscription status within the Data Extension?

I am asking this question because all the relevant documents/help sources I can find suggest that Subscriber List is an integral part of the opt-in processes, but I want to know if I can just achieve this with using only Data Extension. Do we need to use features like Publication List and Suppression List with Data Extensions because Data Extension alone cannot process and maintain subscription status.

Also it is through Publication List and Suppression List that you can use features such as Subscription and Profile Centers, and you can’t set up something similar using Data Extension?

All topic

How do I solve a maze using velocity? The velocity starts and ends as 0

I know how to find the shortest path using A*, but I don’t know how to implement it in terms of velocity. The fact that I have to start with 0 velocity and end at my final destination with 0 velocity throws me off.

All topic

How can I make a transparent hole with shaperenderer using stencil masking in libgdx?

I’m making a 2d game, where I need a resizeable, moveable rectangle outline. I’m trying to use stencil masking to do it by cutting a hole in a solid rectangle, and I thought this would help:

How can I add a transparent overlay to a UI in libGDX?

But all I get is a solid box. Here’s my code:

        Gdx.gl.glClear(GL_STENCIL_BUFFER_BIT);
        Gdx.gl.glColorMask(false, false, false, false);
        Gdx.gl.glDepthMask(false);
        Gdx.gl.glEnable(GL20.GL_STENCIL_TEST);
        Gdx.gl.glStencilFunc(GL20.GL_ALWAYS, 0x1, 0xffffffff);
        Gdx.gl.glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);

        shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);

        shapeRenderer.box(cubby.xpos + 5 , cubby.ypos + 5, 0, cubby.size - 10, cubby.size - 10, 0);

        shapeRenderer.end();

        shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);

        Gdx.gl.glColorMask(true, true, true, true);
        Gdx.gl.glDepthMask(true);

        Gdx.gl.glStencilFunc(GL_NOTEQUAL, 0x1, 0xffffffff);
        Gdx.gl.glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

        shapeRenderer.box(cubby.xpos, cubby.ypos,0,cubby.size, cubby.size, 0);

        shapeRenderer.end();

        Gdx.gl.glDisable(GL20.GL_STENCIL_TEST);

All topic

how to deny ping from one direction but not the other using Access-list

trying to deny ping from 12.12.12.0 network

Hello everyone.

What I’m trying to do is to deny ping access from the 12.12.12.0 network to reach the 10.10.10.0 network but not deny ping access to go from 10.10.10.0 network and reach the 12.12.12.0 network. So basically PC2 and PC3 can’t ping PC0 and PC1 but PC0 and PC1 can or the other way around.

this is what I tried to do so far with no success. It either blocks ping from both sides or allow it.

Router#show run
Building configuration...

Current configuration : 1328 bytes
!
version 12.4
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Router
!
!
!
!
!
!
!
!
no ip cef
no ipv6 cef
!
!
!
!
!
!
!
!
!
!
!
!
spanning-tree mode pvst
!
!
!
!
!
!
interface FastEthernet0/0
 ip address 10.10.10.1 255.255.255.0
 ip access-group 101 out
 duplex auto
 speed auto
!
interface FastEthernet0/1
 no ip address
 duplex auto
 speed auto
 shutdown
!
interface Serial1/0
 ip address 11.11.11.1 255.255.255.0
 ip access-group 101 in
!
interface Serial1/1
 no ip address
 clock rate 2000000
 shutdown
!
interface Serial1/2
 no ip address
 clock rate 2000000
 shutdown
!
interface Serial1/3
 no ip address
 clock rate 2000000
 shutdown
!
interface Serial1/4
 no ip address
 clock rate 2000000
 shutdown
!
interface Serial1/5
 no ip address
 clock rate 2000000
 shutdown
!
interface Serial1/6
 no ip address
 clock rate 2000000
 shutdown
!
interface Serial1/7
 no ip address
 clock rate 2000000
 shutdown
!
interface Vlan1
 no ip address
 shutdown
!
router rip
 network 10.0.0.0
 network 11.0.0.0
 network 12.0.0.0
!
ip classless
!
ip flow-export version 9
!
!
access-list 101 permit icmp host 12.12.12.3 10.10.10.0 0.0.0.255
access-list 101 permit icmp 10.10.10.0 0.0.0.255 any
!
!
!
!
!
line con 0
!
line aux 0
!
line vty 0 4
 login
!
!
!
end

All topic

Is it possible to add a quick status command to Thruk using a plugin?

I’ve looked through the documentation available on Thruk’s website. The information about writing plugins is pretty succinct, and all the example plugins seems to alter, at most, the left menu bar and provide a different main view. I know there is a configuration file to enable/disable the built-in quick status commands, but I’m wondering if it’s possible to add a totally new one via a plugin, and how. I’m hoping to add a ticketing option that let’s one ticket all selected/services nodes.

All topic

Mocha test are not using port specified in ENV in Node/Express

I have a Node/Express 4x project setup using a .env file and a index.js for changing the ports and db based on how i start the app (npm start, npm run dev, etc). It works for everything except mocha test. The type of testing I’m doing is implementation test. In some of these test I make request against test databases that have their parameters defined in .env files.

If i do npm test it executes the following in my package.json:

NODE_ENV=test mocha --timeout 10000

My console.log inside my test show my host headers are always host: '127.0.0.1:34175 or some other random port number. In addition to that, none of the other variables in my .env are being used with npm test.

I have const app = require('../../app'); in my test suite and do not get any errors. app.post and app.get, etc all work fine but my environment is being ignored.

npm start runs the following and works:

NODE_ENV=production node ./bin/www

npm run dev runs the following and works:

NODE_ENV=development node ./bin/www

When i change one of the above to run the NODE_ENV=test they still work and use the appropriate test related .env configurations. Yet if I run npm test mocha ignores/overrides .env. I even tried importing app as exported from bin/www to see if that made any difference and it didn’t help. I also change npm test to execute NODE_ENV=test node ./bin/www just to see if it operated as expected and it did. It’s just not using my .env when its a mocha test.

Test that don’t depend on .env being set properly (like no Mongo or SQL DB calls) work fine. Example test file:

const path = require('path');
const debug = require('debug')(`CUSTOM-DEBUG-TEST:${path.relative(process.cwd(), __dirname)}`);

// process.env.NODE_ENV = 'test';
// const app = require('../../app');
const app = require('../../bin/www');

const chai = require('chai');
const request = require('supertest');
const mongoose = require('mongoose');

const { expect } = chai;

describe('## App is online ', () => {
  it('should reply "Access API Online!" without login', (done) => {
    request(app)
      .get('/access/')
      .end((err, res) => {
        expect(res.statusCode).to.equal(200);
        expect(res.body).to.be.an('object'); 
        expect(res.body.success).to.equal('Access API Online!');
        debug(res.body);
        mongoose.connection.close();
        done();
      });
  });
});

Why isn’t Mocha using the ENV configuration in the same manner?

All topic

DIY electromagnet using copper wire and AC adapter

I want to make for some demonstration (caching some paper clips on ON and doping them on OFF) electromagnet made from copper wire (should it be single wire?) with ferromagnetic inside coil:
enter image description here

As power source I am going to use Panasonic POLV19CE AC ADAPTOR
INPUT: 220-240V ~ 50/60Hz 40mA
OUTPUT: 6V DC 500mA

Is it safe to use this adapter as power source of the?
Is the power of the adapter enough?
The copper wire is enough or it is necessary to add some resistance?

All topic