Skip to content

Commit 2afd241

Browse files
committedApr 4, 2020
Added Node backend
1 parent c0b3367 commit 2afd241

File tree

633 files changed

+135999
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

633 files changed

+135999
-1
lines changed
 
+186
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
2+
#include <SPI.h>
3+
#include <LoRa.h>
4+
#include <GSM.h>
5+
// rst-d0
6+
//nss-d2
7+
//d100-d1
8+
9+
#define PINNUMBER "682020"
10+
int counter = 0;
11+
12+
String oktext = "OK";
13+
String errortext = "ERROR";
14+
15+
char url[] = "arduino.cc";
16+
char urlproxy[] = "http://www.arduino.cc";
17+
char path[] = "/";
18+
String response = "";
19+
boolean use_proxy = false;
20+
21+
22+
23+
void setup() {
24+
Serial.begin(9600);
25+
while (!Serial);
26+
//LoRa.setPins(4, 16, 5);
27+
// LoRa.setSPIFrequency(1E6);
28+
29+
Serial.println("LoRa Sender");
30+
31+
if (!LoRa.begin(433E6)) {
32+
Serial.println("Starting LoRa failed!");
33+
while (1);
34+
}
35+
}
36+
37+
void loop() {
38+
Serial.print("Sending packet: ");
39+
Serial.println(counter);
40+
41+
// send packet
42+
LoRa.beginPacket();
43+
LoRa.print("37.7510,37.7510 ");
44+
LoRa.print(counter);
45+
LoRa.endPacket();
46+
47+
counter++;
48+
49+
delay(8000);
50+
use_proxy = false;
51+
52+
// start GSM shield
53+
// if your SIM has PIN, pass it as a parameter of begin() in quotes
54+
Serial.print("Connecting GSM network...");
55+
if (gsmAccess.begin(PINNUMBER) != GSM_READY) {
56+
Serial.println(errortext);
57+
while (true);
58+
}
59+
Serial.println(oktext);
60+
61+
// read APN introduced by user
62+
char apn[50];
63+
Serial.print("Enter your APN: ");
64+
readSerial(apn);
65+
Serial.println(apn);
66+
67+
// Read APN login introduced by user
68+
char login[50];
69+
Serial.print("Now, enter your login: ");
70+
readSerial(login);
71+
Serial.println(login);
72+
73+
// read APN password introduced by user
74+
char password[20];
75+
Serial.print("Finally, enter your password: ");
76+
readSerial(password);
77+
78+
// attach GPRS
79+
Serial.println("Attaching to GPRS with your APN...");
80+
if (gprsAccess.attachGPRS(apn, login, password) != GPRS_READY) {
81+
Serial.println(errortext);
82+
} else {
83+
84+
Serial.println(oktext);
85+
86+
// read proxy introduced by user
87+
char proxy[100];
88+
Serial.print("If your carrier uses a proxy, enter it, if not press enter: ");
89+
readSerial(proxy);
90+
Serial.println(proxy);
91+
92+
// if user introduced a proxy, asks him for proxy port
93+
int pport;
94+
if (proxy[0] != '\0') {
95+
// read proxy port introduced by user
96+
char proxyport[10];
97+
Serial.print("Enter the proxy port: ");
98+
readSerial(proxyport);
99+
// cast proxy port introduced to integer
100+
pport = (int) proxyport;
101+
use_proxy = true;
102+
Serial.println(proxyport);
103+
}
104+
105+
// connection with arduino.cc and realize HTTP request
106+
Serial.print("Connecting and sending GET request to arduino.cc...");
107+
int res_connect;
108+
109+
// if use a proxy, connect with it
110+
if (use_proxy) {
111+
res_connect = client.connect(proxy, pport);
112+
} else {
113+
res_connect = client.connect(url, 80);
114+
}
115+
116+
if (res_connect) {
117+
// make a HTTP 1.0 GET request (client sends the request)
118+
client.print("GET ");
119+
120+
// if use a proxy, the path is arduino.cc URL
121+
if (use_proxy) {
122+
client.print(urlproxy);
123+
} else {
124+
client.print(path);
125+
}
126+
127+
client.println(" HTTP/1.0");
128+
client.println();
129+
Serial.println(oktext);
130+
} else {
131+
// if you didn't get a connection to the server
132+
Serial.println(errortext);
133+
}
134+
Serial.print("Receiving response...");
135+
136+
boolean test = true;
137+
while (test) {
138+
// if there are incoming bytes available
139+
// from the server, read and check them
140+
if (client.available()) {
141+
char c = client.read();
142+
response += c;
143+
144+
// cast response obtained from string to char array
145+
char responsechar[response.length() + 1];
146+
response.toCharArray(responsechar, response.length() + 1);
147+
148+
// if response includes a "200 OK" substring
149+
if (strstr(responsechar, "200 OK") != NULL) {
150+
Serial.println(oktext);
151+
Serial.println("TEST COMPLETE!");
152+
test = false;
153+
}
154+
}
155+
156+
// if the server's disconnected, stop the client:
157+
if (!client.connected()) {
158+
Serial.println();
159+
Serial.println("disconnecting.");
160+
client.stop();
161+
test = false;
162+
}
163+
}
164+
}
165+
}
166+
167+
/*
168+
Read input serial
169+
*/
170+
int readSerial(char result[]) {
171+
int i = 0;
172+
while (1) {
173+
while (Serial.available() > 0) {
174+
char inChar = Serial.read();
175+
if (inChar == '\n') {
176+
result[i] = '\0';
177+
return 0;
178+
}
179+
if (inChar != '\r') {
180+
result[i] = inChar;
181+
i++;
182+
}
183+
}
184+
}
185+
}
186+
}

‎LoRa1.html

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!DOCTYPE html>
2+
<html lang="en" dir="ltr">
3+
<head>
4+
<meta charset="utf-8">
5+
<title></title>
6+
<style>
7+
#map{
8+
9+
height: 800px;
10+
width: 100%;
11+
}
12+
</style>
13+
</head>
14+
<body>
15+
<div id="map">
16+
17+
</div>
18+
<script>
19+
function initMap(){
20+
//Map Options
21+
var options = {
22+
zoom:15,
23+
center:{lat:10.0554,lng: 76.3551}
24+
}
25+
26+
//New Map
27+
var map = new google.maps.Map(document.getElementById('map'),options);
28+
29+
//Add Marker
30+
// var marker = new google.maps.Marker({
31+
// position:{lat:10.0261,lng: 76.3125},
32+
// map:map
33+
// });
34+
//
35+
// var infoWindow = new google.maps.InfoWindow({
36+
// content:'<h1>Edapally</h1>'
37+
// });
38+
//
39+
// marker.addListener('click',function(){
40+
// infoWindow.open(map,marker);
41+
// });
42+
addMarker({lat:10.0554,lng: 76.3551});
43+
44+
//Add Marker function
45+
function addMarker(coords){
46+
var marker = new google.maps.Marker({
47+
position:coords,
48+
map:map
49+
});
50+
}
51+
52+
}
53+
</script>
54+
<script async defer
55+
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDQptqa10s-pziD9T-ECBMO0viTKbTfkWw&callback=initMap">
56+
</script>
57+
58+
59+
</body>
60+
</html>

0 commit comments

Comments
 (0)
Please sign in to comment.