Skip to content

Commit

Permalink
Echec de communication 3G avec le serveur...
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor333Huesca committed Mar 25, 2018
1 parent 59ecb36 commit 92c00d0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .vscode/arduino.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"board": "waspmote:avr:wasp1",
"port": "/dev/ttyUSB0",
"sketch": "Waspmote/sms/sms.ino",
"sketch": "Waspmote/3g/3g.ino",
"output": "Waspmote/build"
}
5 changes: 5 additions & 0 deletions Site_Web/public_html/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<?php
if (isset($_POST['varA'])) {
echo $_POST['varA'];
if (file_put_contents('varA.log', $_POST['varA'], FILE_APPEND)) {
// Données enregistrées
} else {
// Error
}
}
?>
</body>
Expand Down
55 changes: 37 additions & 18 deletions Waspmote/3g/3g.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <WaspPWR.h>
#include <WaspConstants.h>
#include <Wasp3G.h>
#include <stdio.h>
#include <string.h>


// Declare globales object to bybass parsing bug, only used for Visual Studio Code.
Expand All @@ -17,17 +19,23 @@ Wasp3G _3G;

int8_t answer;
const char *pin_code = "1234";
const char *sim_apn = "free";

const char *srv_url = "https://lemuriens.proj.info-ufr.univ-montp2.fr/";
const char *srv_url = "https://lemuriens.proj.info-ufr.univ-montp2.fr";
const char *srv_page = "index.php";
// const char *srv_url = "162.38.151.137";
// const char *srv_url = "http://localhost";
const uint16_t srv_port = 80;
const uint8_t *srv_data = (const uint8_t*)"varA=1";
const char *srv_data = "varA='Test_des_lemuriens'";

void setup()
{
// Setup for Serial port over USB:
USB.ON();
USB.println(F("USB port started..."));

USB.printf("Lets connect to %s to send the following text :\n\"%s\"\n", srv_url, srv_data);

// 1. activates the 3G module:
answer = _3G.ON();
if ((answer == 1) || (answer == -3))
Expand All @@ -36,7 +44,7 @@ void setup()

// 2. sets pin code:
USB.println(F("Setting PIN code..."));
// **** must be substituted by the SIM code

if (_3G.setPIN(pin_code) == 1)
{
USB.println(F("PIN code accepted"));
Expand All @@ -47,35 +55,46 @@ void setup()
}

// 3. waits for connection to the network
answer = _3G.check(180);
answer = _3G.check(180);
if (answer == 1)
{
USB.println(F("3G module connected to the network..."));
// 4. sends an SMS
if (_3G.setTextModeSMS())

_3G.set_APN((char *)sim_apn);

// 4. sends an HTTP request
answer = _3G.sendHTTPframe((const char*) srv_url, (uint16_t) srv_port, (uint8_t*) srv_data, (int) sizeof(srv_data), (uint8_t) POST, (uint8_t) 0);
if ( answer == 1)
{
// Success
USB.println(F("SMS mode successfully set up"));
USB.println(F("HTTP request successfuly sent"));
}
else if (answer == 0)
{
USB.println(F("No connection"));
}
else
{
// Error
USB.println(F("Error setting SMS mode"));
USB.println(F("Error sending request"));
USB.print(F("CMS error code:"));
USB.println(answer, DEC);
USB.print(F("CMS error code: "));
USB.println(_3G.CME_CMS_code, DEC);
}

//answer = _3G.sendHTTPframe(srv_url, srv_port, srv_data, (int)sizeof(srv_data), (uint8_t)POST);

// 5. gets URL from the solicited URL
USB.print(F("Getting URL with POST method..."));
char tmp[256];
sprintf(tmp, "POST %s HTTP/1.1\r\nHost: %s\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %d\r\n\r\n%s", srv_page, srv_url, strlen(srv_data), srv_data);

answer = _3G.readURL("test.libelium.com", srv_port, tmp);
if ( answer == 1)
{
USB.println(F("SMS Sent OK"));

}
else if (answer == 0)
{
USB.println(F("No connection"));
USB.println(F("HTTP request successfuly sent"));
}
else
{
USB.println(F("Error sending sms"));
USB.println(F("Error sending request"));
USB.print(F("CMS error code:"));
USB.println(answer, DEC);
USB.print(F("CMS error code: "));
Expand Down

0 comments on commit 92c00d0

Please sign in to comment.