user54650: I want to control an RC car with a joystick in mobile. Currently, I can only make the motor move forward and backward but not able to control the speed. Node mcu is used as a processor to receive the message.
Here is the code below:-

#include <ESP8266WiFi.h>
#define PubNub_BASE_CLIENT WiFiClient
#include <PubNub.h>
#define PUBNUB_DEFINE_STRSPN_AND_STRNCASECMP
#include <L298N.h>

const char *ssid =  "mym404";     // replace with your wifi ssid and wpa2 key
const char *pass =  "786110786";

const char * pubkey = "";
const char * subkey = "";

const char * subchannel = "base";

#define ENB D6
#define IN1 D3
#define IN2 D4

L298N motorL(ENB, IN1, IN2);


#define ENA D5
#define IN3 D1
#define IN4 D7

L298N motorR(ENA, IN3, IN4);


void setup() {
    /* For debugging, set to speed of your choice */
    Serial.begin(115200);


       Serial.println("Connecting to ");
       Serial.println(ssid); 

       WiFi.begin(ssid, pass); 
       while (WiFi.status() != WL_CONNECTED) 
          {
            delay(500);
            Serial.print(".");
          }
      Serial.println("");
      Serial.println("WiFi connected");

    /* Start the Pubnub library by giving it a publish and subscribe
       keys */
    PubNub.begin(pubkey, subkey);

}

void loop() {

  int tim = millis();



    PubSubClient *sclient = PubNub.subscribe(subchannel);
    if (!sclient) return; // error
    String msg;
    SubscribeCracker ritz(sclient);
    if (!ritz.finished()) {
        ritz.get(msg);
        if (msg.length() > 0) {
            Serial.print("Received: "); Serial.println(msg);

            String X = getStringPartByNr(msg, ':', 0);
            String Y = getStringPartByNr(msg, ':', 1);

            X.remove(0,1);

            int Xcord = X.toInt();
            int Ycord = Y.toInt();

            Serial.print("X: "); Serial.println(Xcord);
            Serial.print("Y: "); Serial.println(Ycord);

            int angle;
            int throttle = (Xcord + Ycord)/2;



            if ((Xcord > 100) && (Ycord > 100)) {
              angle = round(atan2(Ycord-100,Xcord-100)*(180/3.14));
              motorR.forward();
              motorL.forward();
              motorR.setSpeed(abs(int(throttle*sin(angle))));
              motorL.setSpeed(throttle);
              Serial.print("R speed: "); Serial.println(abs(int(throttle*sin(angle))));
              Serial.print("L speed: "); Serial.println(throttle); 
              //motorR.forward();
              //motorL.forward();
            }
            else if ((Xcord < 100) && (Ycord > 100)) {
              angle = 180 - round(atan2(Ycord-100,100-Xcord)*(180/3.14));

              motorR.setSpeed(throttle);
              motorL.setSpeed(abs(int(throttle*sin(angle))));
              Serial.print("R speed: "); Serial.println(throttle);
              Serial.print("L speed: "); Serial.println(abs(int(throttle*sin(angle))));
              motorR.forward();
              motorL.forward();
            }
            else if ((Xcord < 100) && (Ycord < 100)) {
              angle = 180 + round(atan2(100-Ycord,100-Xcord)*(180/3.14));

              motorR.setSpeed(200-throttle);
              motorL.setSpeed(abs(int((200-throttle)*sin(angle)*(-1))));
              Serial.print("R speed: "); Serial.println(200-throttle);
              Serial.print("L speed: "); Serial.println(abs(int((200-throttle)*sin(angle)*(-1))));
              motorR.backward();
              motorL.backward();
            }
            else if ((Xcord > 100) && (Ycord < 100)) {
              angle = 270 + round(atan2(Xcord-100,100-Ycord)*(180/3.14));
              motorR.setSpeed(abs(int((200-throttle)*sin(angle)*(-1))));
              motorL.setSpeed(200-throttle);
              Serial.print("R speed: "); Serial.println(abs(int((200-throttle)*sin(angle)*(-1))));
              Serial.print("L speed: "); Serial.println(200-throttle);
              motorR.backward();
              motorL.backward();
            }

            Serial.print("Angle: "); Serial.println(angle);
            //Serial.print("time: "); Serial.println(tim);



        }
    }



    sclient->stop();


}

String getStringPartByNr(String data, char separator, int index)
{
    // splitting a string and return the part nr index
    // split by separator

    int stringData = 0;        //variable to count data part nr 
    String dataPart = "";      //variable to hole the return text

    for(int i = 0; i<data.length()-1; i++) {    //Walk through the text one letter at a time

      if(data[i]==separator) {
        //Count the number of times separator character appears in the text
        stringData++;

      }else if(stringData==index) {
        //get the text when separator is the rignt one
        dataPart.concat(data[i]);

      }else if(stringData>index) {
        //return text and stop if the next separator appears - to save CPU-time
        return dataPart;
        break;

      }

    }
    //return text if this is the last part
    return dataPart;
}

Port Reading:-

What can the problem be?

user55142: That's  because the l298n library are used for the arduino or other microcontroller that have hardware PWM in their systems. The library using hardware pwm by generating pulses and make variations of the cyclic rapport aka "alpha" . 
Esp8266 have no pwm in their systems 
So try to use software pwm library for the esp8266 

this is the link. https://www.arduinolibraries.info/libraries/soft-pwm

Also don't include that library and try to make it work using easy lines of codes. 

54650: <p>I want to control an RC car with a joystick in mobile. Currently, I can only make the motor move forward and backward but not able to control the speed. Node mcu is used as a processor to receive the message.</p>

<p>Here is the code below:-
</p>

<pre class="lang-cpp prettyprint-override"><code>#include &lt;ESP8266WiFi.h&gt;
#define PubNub_BASE_CLIENT WiFiClient
#include &lt;PubNub.h&gt;
#define PUBNUB_DEFINE_STRSPN_AND_STRNCASECMP
#include &lt;L298N.h&gt;

const char *ssid =  "mym404";     // replace with your wifi ssid and wpa2 key
const char *pass =  "786110786";

const char * pubkey = "";
const char * subkey = "";

const char * subchannel = "base";

#define ENB D6
#define IN1 D3
#define IN2 D4

L298N motorL(ENB, IN1, IN2);


#define ENA D5
#define IN3 D1
#define IN4 D7

L298N motorR(ENA, IN3, IN4);


void setup() {
    /* For debugging, set to speed of your choice */
    Serial.begin(115200);


       Serial.println("Connecting to ");
       Serial.println(ssid); 

       WiFi.begin(ssid, pass); 
       while (WiFi.status() != WL_CONNECTED) 
          {
            delay(500);
            Serial.print(".");
          }
      Serial.println("");
      Serial.println("WiFi connected");

    /* Start the Pubnub library by giving it a publish and subscribe
       keys */
    PubNub.begin(pubkey, subkey);

}

void loop() {

  int tim = millis();



    PubSubClient *sclient = PubNub.subscribe(subchannel);
    if (!sclient) return; // error
    String msg;
    SubscribeCracker ritz(sclient);
    if (!ritz.finished()) {
        ritz.get(msg);
        if (msg.length() &gt; 0) {
            Serial.print("Received: "); Serial.println(msg);

            String X = getStringPartByNr(msg, ':', 0);
            String Y = getStringPartByNr(msg, ':', 1);

            X.remove(0,1);

            int Xcord = X.toInt();
            int Ycord = Y.toInt();

            Serial.print("X: "); Serial.println(Xcord);
            Serial.print("Y: "); Serial.println(Ycord);

            int angle;
            int throttle = (Xcord + Ycord)/2;



            if ((Xcord &gt; 100) &amp;&amp; (Ycord &gt; 100)) {
              angle = round(atan2(Ycord-100,Xcord-100)*(180/3.14));
              motorR.forward();
              motorL.forward();
              motorR.setSpeed(abs(int(throttle*sin(angle))));
              motorL.setSpeed(throttle);
              Serial.print("R speed: "); Serial.println(abs(int(throttle*sin(angle))));
              Serial.print("L speed: "); Serial.println(throttle); 
              //motorR.forward();
              //motorL.forward();
            }
            else if ((Xcord &lt; 100) &amp;&amp; (Ycord &gt; 100)) {
              angle = 180 - round(atan2(Ycord-100,100-Xcord)*(180/3.14));

              motorR.setSpeed(throttle);
              motorL.setSpeed(abs(int(throttle*sin(angle))));
              Serial.print("R speed: "); Serial.println(throttle);
              Serial.print("L speed: "); Serial.println(abs(int(throttle*sin(angle))));
              motorR.forward();
              motorL.forward();
            }
            else if ((Xcord &lt; 100) &amp;&amp; (Ycord &lt; 100)) {
              angle = 180 + round(atan2(100-Ycord,100-Xcord)*(180/3.14));

              motorR.setSpeed(200-throttle);
              motorL.setSpeed(abs(int((200-throttle)*sin(angle)*(-1))));
              Serial.print("R speed: "); Serial.println(200-throttle);
              Serial.print("L speed: "); Serial.println(abs(int((200-throttle)*sin(angle)*(-1))));
              motorR.backward();
              motorL.backward();
            }
            else if ((Xcord &gt; 100) &amp;&amp; (Ycord &lt; 100)) {
              angle = 270 + round(atan2(Xcord-100,100-Ycord)*(180/3.14));
              motorR.setSpeed(abs(int((200-throttle)*sin(angle)*(-1))));
              motorL.setSpeed(200-throttle);
              Serial.print("R speed: "); Serial.println(abs(int((200-throttle)*sin(angle)*(-1))));
              Serial.print("L speed: "); Serial.println(200-throttle);
              motorR.backward();
              motorL.backward();
            }

            Serial.print("Angle: "); Serial.println(angle);
            //Serial.print("time: "); Serial.println(tim);



        }
    }



    sclient-&gt;stop();


}

String getStringPartByNr(String data, char separator, int index)
{
    // splitting a string and return the part nr index
    // split by separator

    int stringData = 0;        //variable to count data part nr 
    String dataPart = "";      //variable to hole the return text

    for(int i = 0; i&lt;data.length()-1; i++) {    //Walk through the text one letter at a time

      if(data[i]==separator) {
        //Count the number of times separator character appears in the text
        stringData++;

      }else if(stringData==index) {
        //get the text when separator is the rignt one
        dataPart.concat(data[i]);

      }else if(stringData&gt;index) {
        //return text and stop if the next separator appears - to save CPU-time
        return dataPart;
        break;

      }

    }
    //return text if this is the last part
    return dataPart;
}
</code></pre>

<p>Port Reading:-
<a href="https://i.stack.imgur.com/FcCC4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FcCC4.jpg" alt="enter image description here"></a></p>

<p>What can the problem be?</p>
 55142: <p>That's  because the l298n library are used for the arduino or other microcontroller that have hardware PWM in their systems. The library using hardware pwm by generating pulses and make variations of the cyclic rapport aka "alpha" . 
Esp8266 have no pwm in their systems 
So try to use software pwm library for the esp8266 </p>

<blockquote>
  <p>this is the link. <a href="https://www.arduinolibraries.info/libraries/soft-pwm" rel="nofollow noreferrer">https://www.arduinolibraries.info/libraries/soft-pwm</a></p>
</blockquote>

<p>Also don't include that library and try to make it work using easy lines of codes. </p>
