Cooking Hacks Forum https://www.cooking-hacks.com/forum/ |
|
Examples of use WiFi Pro module with Arduino https://www.cooking-hacks.com/forum/viewtopic.php?f=19&t=10798 |
Page 1 of 1 |
Author: | novichkov [ Tue Oct 24, 2017 4:55 pm ] |
Post subject: | Examples of use WiFi Pro module with Arduino |
Hi dev, we don't find any examples for use WiFi PRO module with Arduino over XBee Shield, is it even possible? If yes, please support us for configure SSID and sending GET HTTP request on the server. Regards, Serafim! |
Author: | libelium-dev [ Wed Oct 25, 2017 7:08 am ] |
Post subject: | Re: Examples of use WiFi Pro module with Arduino |
Hi novichkov, Here you have got an example to use with WiFr PRO. We haven't got more example developed to use with Arduino with this module: Code: /* * Wifi Module * * Copyright (C) Libelium Comunicaciones Distribuidas S.L. * http://www.libelium.com * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * a * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. * * Version: 1.0 * Design: David Gascón * Implementation: Jorge Casanova */ //Enter here your data const char wifi_ssid[] = "libelium_wsn2"; const char wifi_password[] = "libelium.2012_"; const char server[] = "http://test.libelium.com"; const char server_port[] = "80"; const char GET[] = "test-get-post.php?a=1&b=2"; // Global variables int8_t answer; char response[300]; char aux_str[90]; #define DATA_BUFFER 1024 String inputLine = ""; // a string to hold incoming line void setup() { //Write here you correct baud rate Serial.begin(115200); wifireset(); wificonfig(); // reserve DATA_BUFFER bytes for the inputString: inputLine.reserve(DATA_BUFFER); } void loop() { Serial.println(F("INICIO DEL LOOP")); Serial.println(F("Sending HTTP GET")); sendGET(); Serial.println(F("FINAL DEL LOOP")); delay(10000); } //********************************************** void wifireset() { Serial.println(F("Setting Wifi parameters")); sendCommand("AT+iFD\r","I/OK",2000); delay(1000); sendCommand("AT+iDOWN\r","I/OK",2000); delay(6000); } //********************************************** void wificonfig() { Serial.println(F("Setting Wifi parameters")); sendCommand("AT+iFD\r","I/OK",2000); delay(2000); snprintf(aux_str, sizeof(aux_str), "AT+iWLSI=%s\r", wifi_ssid); answer = sendCommand(aux_str,"I/OK",10000); if (answer == 1){ snprintf(aux_str, sizeof(aux_str), "Joined to \"%s\"", wifi_ssid); Serial.println(aux_str); delay(5000); } else { snprintf(aux_str, sizeof(aux_str), "Error joining to: \"%s\"", wifi_ssid); Serial.println(aux_str); delay(1000); } snprintf(aux_str, sizeof(aux_str), "AT+iWPP0=%s\r", wifi_password); sendCommand(aux_str,"I/OK",20000); delay(1000); if (answer == 1){ snprintf(aux_str, sizeof(aux_str), "Connected to \"%s\"", wifi_ssid); Serial.println(aux_str); delay(5000); } else { snprintf(aux_str, sizeof(aux_str), "Error connecting to: \"%s\"", wifi_ssid); Serial.println(aux_str); delay(1000); } sendCommand("AT+iDOWN\r","I/OK",2000); delay(6000); } //********************************************** void sendGET() { snprintf(aux_str, sizeof(aux_str), "AT+iRLNK:\"%s:%s/%s\"\r", server, server_port, GET); sendCommand(aux_str,"I/OK",5000); Serial.print("GET response:"); delay(1000); handleSerial(); } //********************************************** int8_t sendCommand(const char* Command, const char* expected_answer, unsigned int timeout){ uint8_t x=0, answer=0; unsigned long previous; memset(response, 0, 300); // Initialize the string delay(100); while( Serial.available() > 0) Serial.read(); // Clean the input buffer Serial.println(Command); // Send Command x = 0; previous = millis(); // this loop waits for the answer do{ if(Serial.available() != 0){ // if there are data in the UART input buffer, reads it and checks for the asnwer response[x] = Serial.read(); x++; // check if the desired answer is in the response of the module if (strstr(response, expected_answer) != NULL) { answer = 1; } } } // Waits for the asnwer with time out while((answer == 0) && ((millis() - previous) < timeout)); return answer; } //********************************************** void handleSerial() { inputLine = ""; while (Serial.available()) { // get the new byte: char inChar = (char)Serial.read(); // latency delay for 115200 (worst condition) delayMicroseconds(105); // add it to the inputString: inputLine += inChar; } Serial.print(inputLine); inputLine = ""; delay(100); } Regards |
Author: | novichkov [ Sun Feb 11, 2018 2:03 pm ] |
Post subject: | Re: Examples of use WiFi Pro module with Arduino |
Hi dev, thanks for your code. Do you have more examples for use this WiFi-module with Arduino, like for waspmote on this: (http://www.libelium.com/development/was ... n-examples)? Especially interesting examples of code for HTTPS GET/POST, TCP/UDP socket usage, FTP usage and IP static config. Regards, Serafim! |
Author: | libelium-dev [ Mon Feb 12, 2018 8:04 am ] |
Post subject: | Re: Examples of use WiFi Pro module with Arduino |
Hi novichkov, Sorry but we haven't got more examples to use with WiFi PRO. You need to develop it. You can see the Waspmote libraries and examples and try to implement them. Regards. |
Page 1 of 1 | All times are UTC + 1 hour |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |