How to use THINGER.IO Library, Controlling RC car over the internet (SOLVED)

Hello.

I'm using an IoT platform with my ESP8266 called "Thinger.io"
It's similar to "Blynk" platform.

This is its sample code:

#include <ThingerESP8266.h>

#define USERNAME "erfan_m14"
#define DEVICE_ID "ESP8266"
#define DEVICE_CREDENTIAL "???????"

#define SSID "********"
#define SSID_PASSWORD "******"

ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);

  thing.add_wifi(SSID, SSID_PASSWORD);

  // digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc)
  thing["led"] << digitalPin(LED_BUILTIN);

  // resource output example (i.e. reading a sensor value)
  thing["millis"] >> outputValue(millis());

  // more details at http://docs.thinger.io/arduino/
}

void loop() {
  thing.handle();
}

What I want to do is to use it with a motor driver with 2 motors to build a RC Car. So imagine I have 4 buttons on my phone browser (4 switches actually): Forward, Backward, Right and Left

Pins 1 and 2 control the right motor, pins 3 and 4 control the left motor.

When I turn on "forward" switch, both pins 2 and 4 should go HIGH, and When "backward" both pins 1 and 3 Should HIGH, for turning right pins 4 and 1 should go HIGH and to turn left, pins 2 and 3.

The problem is as you can see in the sample code, I should first set a pin for every button and then the library does the rest, I mean it knows when button is switched on, the pins should go HIGH, so just one pin for every button.

I think I can use 4 pins and every pin is connected to two inputs of the driver so each pin moves the car forward or backward or left or right.

But is there any solution to do my project without changing the wiring from Arduino to motor driver? I mean that every pin is connected to one input of the driver.

This is C/C++. What makes you think that an array may be addressed with a string?

vaj4088:
This is C/C++. What makes you think that an array may be addressed with a string?

What makes you think it may not?

class SomeThing 
{
    ···
    SomeType operator[](const char *str)
    {
        ···
    }
};

erfan_m14:
The problem is as you can see in the sample code, I should first set a pin for every button and then the library does the rest, I mean it knows when button is switched on, the pins should go HIGH, so just one pin for every button.

You need to post a link to the documentation for the ThingerESP8266.h library.

In your example you are using the library to change the value of an I/O pin. What you need to be able to do is use the library to call another function into which you can put whatever code you need.

...R

Robin2:
You need to post a link to the documentation for the ThingerESP8266.h library.

In your example you are using the library to change the value of an I/O pin. What you need to be able to do is use the library to call another function into which you can put whatever code you need.

...R

Here is the link.

Thank you so much for your help.

Suggest renaming thread to something mentioning thinger.io - since the only people who will be able to help here are people familiar with thinger.io - I looked at it briefly, and it was quickly clear that learning enough to be able to answer your question would take more time than I would spend just to answer a forum question, and the subject matter was boring too! (I am sick to death of these two-bit IoT platforms, each with their own idea of how things should be done (this one seems particularly bizarre in that regard!)

DrAzzy:
Suggest renaming thread to something mentioning thinger.io - since the only people who will be able to help here are people familiar with thinger.io - I looked at it briefly, and it was quickly clear that learning enough to be able to answer your question would take more time than I would spend just to answer a forum question, and the subject matter was boring too! (I am sick to death of these two-bit IoT platforms, each with their own idea of how things should be done (this one seems particularly bizarre in that regard!)

Hello, thank you for your reply and sorry for taking your time. Actually I thought it can be done in a way without using this library codes but common codes, so I didn’t mention the library name. How can I rename a thread by the way?

DrAzzy:
Suggest renaming thread to something mentioning thinger.io - since the only people who will be able to help here are people familiar with thinger.io - I looked at it briefly, and it was quickly clear that learning enough to be able to answer your question would take more time than I would spend just to answer a forum question, and the subject matter was boring too! (I am sick to death of these two-bit IoT platforms, each with their own idea of how things should be done (this one seems particularly bizarre in that regard!)

I renamed it.
Thank you

erfan_m14:
Here is the link.

That link is for a ZIP file which I have no wish to download - there is enough of my own junk on this PC.

This page refers to a function called set_function() but I don't know how it should be used and I don't plan to take the time to learn all about Thinger.

...R

oqibidipo, that is a very interesting usage of C++. I was wrong. Thank you.

Robin2:
That link is for a ZIP file which I have no wish to download - there is enough of my own junk on this PC.

This page refers to a function called set_function() but I don't know how it should be used and I don't plan to take the time to learn all about Thinger.

...R

Thank you for your help.
I just found a good solution and will post it as soon as I finish writing the codes.

I used this tutorial to solve my Problem.

Actually I added a "THING" like this:

thing["motors"]["right"] = [](){
       digitalWrite(l1, HIGH);
       digitalWrite(l2, LOW);
       digitalWrite(r1, LOW);
       digitalWrite(r2, HIGH);
    };

Then I created a very simple webpage to call this "THING" using api.

It took me a lot of time to do these because it was all new to me so for anyone like me, you can google "how to send POST or GET request using javascript".

Thanks for the update

It would be useful if you can post the complete program.

...R

Robin2:
Thanks for the update

It would be useful if you can post the complete program.

...R

#include <ThingerESP8266.h>

#define l1 D4 //pin 1 motor left
#define l2 D5 //pin 2 motor left
#define r1 D6 //pin 1 motor right
#define r2 D7 //pin 2 motor right

#define USERNAME "******"
#define DEVICE_ID "******" 
#define DEVICE_CREDENTIAL "******"  

#define SSID "********"
#define SSID_PASSWORD "******"

ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

void setup() {
  
  pinMode(l1, OUTPUT);
  pinMode(l2, OUTPUT);
  pinMode(r1, OUTPUT);
  pinMode(r2, OUTPUT);


  thing.add_wifi(SSID, SSID_PASSWORD);

     thing["motors"]["forward"] = [](){ 

       digitalWrite(l1, HIGH);
       digitalWrite(l2, LOW);
       digitalWrite(r1, HIGH);
       digitalWrite(r2, LOW);
       
    };

    thing["motors"]["back"] = [](){

       digitalWrite(l1, LOW);
       digitalWrite(l2, HIGH);
       digitalWrite(r1, LOW);
       digitalWrite(r2, HIGH);
       
    };


    thing["motors"]["right"] = [](){
  
       digitalWrite(l1, HIGH);
       digitalWrite(l2, LOW);
       digitalWrite(r1, LOW);
       digitalWrite(r2, HIGH);
      
    };

    thing["motors"]["left"] = [](){
    
       digitalWrite(l1, LOW);
       digitalWrite(l2, HIGH);
       digitalWrite(r1, HIGH);
       digitalWrite(r2, LOW);
       
    };

    thing["motors"]["stop"] = [](){

       digitalWrite(l1, LOW);
       digitalWrite(l2, LOW);
       digitalWrite(r1, LOW);
       digitalWrite(r2, LOW);
    };

  
}


void loop() {
  thing.handle();
}

After adding these to your codes, then login to your account in Thinger.IO, go to "devices", select your device, select "view api" (your device should be online), then you will see all these 4 commands: motors > forward, motors>back, motors>right, motors>left, Motors>stop

You can click "Run" to test each of them. And then You should click on "show query" you will see instructions of how to run that THING using api commands. You can use them to create your android application for example or a simple webpage like me or ...

For example to create a webpage:

<div class="row" style="position:absolute; right:0%; top:20%; left:0%; height: 20%; padding-bottom:1em">
          <div class="col-xs-4" style="height: 100%; text-align: center">
            <button id="left" type="button" class="btn btn-default" style="background-color: Transparent; background-repeat:no-repeat; cursor:pointer; overflow: hidden; height: 100%; width: 100%" onmousedown='sendData("left")' onmouseup='sendData("stop")' ontouchstart='sendData("left")' ontouchend='sendData("stop")'>Left</button>
          </div>
function sendData(data){
        if(data === "left"){
            var request = new XMLHttpRequest();
            request.open('GET', 'THE URL WHICH THINGER.IO GIVES YOU', true);
            request.setRequestHeader("Authorization", "Bearer TOKEN WHICH THINGER.IO GIVES YOU");
            request.send();
        }