Don’t forget it!!
Disconnect your arduino from the wifi module when you load the program to your arduino. Already that is programmed your arduino, now you can connect your wifi module and Ready!
Don’t forget it!!
Disconnect your arduino from the wifi module when you load the program to your arduino. Already that is programmed your arduino, now you can connect your wifi module and Ready!
Thanks a lot buddy. My values are now showing up on Ubidots.
I found the error. the code that you provided works with 115200 baud rate if i change the baud rate to 9600 is doesn’t works. So i install 115200 baud rate firmware to my ESP8266-01 and then try the code and it works. Again thank you so much you saved me…
Great
Congratulations and a lot of success !!
Regards.
Why it sends data successfully and in 2nd try it fails and then then successfully… 1 send 1 fail and continues
Hi.
I want to transfer data with AT commands with a Quectel BC95 modem.
What do you think is this possible with your solution?
It is not a normal modem, it has an NB-IoT chip (Narrow Band IoT). The way I sent data is :
Create a socket with AT+NSOCR (UDP)
Sending data(hexa) with AT+NSOST
The data could be a CPU temperature or something like this. But I want to use this special network (NB-IoT) and I want to control with a Raspberry Pi 3. My problem is how can I send data to Ubidots.
Thanks!
Attila
Hi there, I advise you first than all to test the UDP or TCP script example provided by the manufacturer of your board and understand how to properly implement the connection using the AT commands for your board. Once you make this ‘pre-flight’, you should build the payload as the article below explains:
http://help.ubidots.com/developer-guides/send-data-to-ubidots-over-tcp-or-udp
If you wish to understand how to implement a TCP or UDP connection to our server, this article will be useful also for you:
http://help.ubidots.com/developer-guides/sending-tcpudp-packets-using-netcat
Regards
Hi!
I can’t use this to send data for my “server”. I can only use my modem to do that, with AT commands. I want an AT command to use this mobile network to transfer data.
Thanks,
Attila
http://www.c-dis.net/media/images/upload/Quectel_BC95_AT_Commands_Manual_V1.8.pdf
Check it. There are AT commands for your Device… You just look for configuration commands and then send the JSON. I haven’t used this module but I think is not too diferente. Good look!
Hi, I’m using your solution and I succeeded to send data to Ubidots.
But further, I want to get data from ubidots and use it to control motor speed.
Can you help me to do it?
I’m using ESP-01 and arduino Mega. And sending 3 data and wanna receive 2 data from Ubidots
Hi my friend.
Of course, I can help you. Let and wait me a day for generate the code. Regards!
Thanks for your kindness!
Here is my code and I have problem at receiving motor speed(Mspeed) and switch function from Ubidots.
#include <DHT.h>
#define DHTPIN 2 // SDA pin setting
#define DHTTYPE DHT22 // DHT22 (AM2302) sensor type
DHT dht(DHTPIN, DHTTYPE);
// Motor control
int IN1 = 7;
int IN2 = 8;
int ENA = 6; // Motor speed control pin
int TempLimit = 30; // Temperature condition to run motor
int HumiLimit = 50; // Humidity condition to run motor
#define ssid "****" // Put here your SSID
#define password "****" // Put here your PASSWORD
#define id1 "*************" // Put here your Ubidots variable ID1 temp
#define id2 "*************" // Put here your Ubidots variable ID2 humi
#define id3 "*************" // Put here your Ubidots variable ID3 speed
#define id4 "*************" // Put here your Ubidots variable ID4 speed control
#define id5 "*************" // Put here your Ubidots variable ID5 switch
#define token "**************" // Put here your Ubidots TOKEN
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("\nModule Settings WiFi ESP8266");
pinMode(IN1,OUTPUT);
pinMode(IN2,OUTPUT);
sendCmd("AT+RESTORE", "R", 1000); // cmd AT+RESTORE: Restores the Factory Default Settings
sendCmd("AT+RST", "WiFi Module Ready!", 1000); // cmd AT+RST: Restarts the Module
sendCmd("AT+CWMODE=3", "Ap+Station Mode", 1000); // cmd AT+CWMODE=3: Sets the Wi-Fi Ap + Station Mode
sendCmd("AT+CWJAP=\""ssid"\",\""password"\"", "Successful WiFi Connection!", 5000); // cmd AT+CWJAP: Connects to an AP
sendCmd("AT+CIPMUX=1", "Enable Multiple Connections!", 500); // cmd AT+CIPMUX=1: Enable Multiple Connections
}
void loop() {
// put your main code here, to run repeatedly:
float dato1 = dht.readTemperature();
float dato2 = dht.readHumidity();
float Mspeed;
float Switch;
receive_D(Mspeed, Switch, 2);
send_D(dato1, dato2, Mspeed, 3); // The last parameter "3", is for choose the number of variables to send to Ubidots: (1-3)
//Motor control process
if (((float)dato1) > TempLimit || ((float)dato2) > HumiLimit) {
if(Switch==1){
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
analogWrite(ENA, Mspeed);
}
else{
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
}
}
else{
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
}
}
//Maybe, here I need code to receive motor speed and switch float data from Ubidots
// Function to send data from Ubidots *************************************************************************************************************
void send_D(float d1, float d2, int d3, int n_var) { // Send float data
int string_length = 0, long_json = 0, SEND = 0;
String Inicio, Final, variable[10];
// JSON
Inicio = "[";
variable[1] = "{\"variable\": \"" + String(id1) + "\",\"value\":" + String(d1);
variable[2] = "}, {\"variable\": \"" + String(id2) + "\",\"value\":" + String(d2);
variable[3] = "}, {\"variable\": \"" + String(id3) + "\",\"value\":" + String(d3);
Final = "}]";
for(int i = 1; i <= n_var; i++) {
string_length += variable[i].length();
}
long_json = string_length + Inicio.length() + Final.length();
// Serial.println(long_json);
String send1, send2, send3, send4, send5;
int long_post = 0;
// POST
send1 = "POST /api/v1.6/collections/values/ HTTP/1.1\r\n";
long_post = send1.length();
send2 = "Content-Type: application/json\r\nContent-Length: ";
long_post += send2.length();
send3 = String(long_json) + "\r\nX-Auth-Token: ";
long_post += send3.length();
send4 = String(token);
long_post += send4.length();
send5 = "Host: things.ubidots.com\r\n";
long_post += send5.length();
SEND = long_json + long_post + 5;
// Serial.println(SEND);
Serial.println(F("\n**********************************************************************************************************************************************************************\n"));
Flush();
Serial.println(F("AT+CIPSTART=4,\"TCP\",\"things.ubidots.com\",80")); // cmd AT+CIPSTART: Establishes TCP Connection
delay(5000);
Flush();
Serial.println("AT+CIPSEND=4," + String(SEND)); // cmd AT+CIPSEND: Sends Data
delay(500);
Serial.print(send1);
Serial.print(send2);
Serial.print(send3);
Serial.println(send4);
Serial.println(send5);
delay(500);
Serial.print(Inicio);
for(int i = 1; i <= n_var; i++) {
Serial.print(variable[i]);
}
Serial.println(Final);
}
// Function for AT commands *********************************************************************************************************************
void sendCmd(char* cmd, char* ans, int t) {
boolean Er = true;
Flush();
Serial.println(cmd);
delay(t);
while(Serial.available()) {
if(Serial.find("OK")) {
if(ans == "R") {
delay(500);
Serial.print(".");
delay(500);
Serial.print(".");
delay(500);
Serial.println(".\n");
delay(1000);
}
else {
Serial.println(ans);
delay(500);
}
Er = false;
}
}
if(Er == true) {
Serial.println("Error");
delay(500);
if(ans == "Successful WiFi Connection!") {
if(Er == true) {
Serial.println("WiFi Disconnected!");
delay(500);
}
}
}
}
// Function to clean Buffer Serial **************************************************************************************************************
void Flush() {
byte w = 0;
for (int i = 0; i < 10; i++) {
while (Serial.available() > 0) {
char k = Serial.read();
w++;
delay(1);
}
delay(1);
}
}
Hi my friend.
Process is going well?
I also finding solution to get data, but I couldn’t find appropriate method, yet
Hi my friend, I’m waiting for your response
Are there some problems?
Sorry my friend.
I have been very busy, really sorry. Do have you found how to do it?
Not yet
I couldn’t find the way to get and send data simultaneously with AT command.
You can see my code above.
I need your help my friend!
At my arduino MEGA, ESP-01, DHT22 and fan motor is linked to.
Algorithm of fan works well.
If I can get Mspeed and Switch value from server, all the problems will be solved!
you’re going to use a slider, right?
Yes! I want to get Mspeed value from slider and get Switch value from switch.