Cécilia Facca in MATLAB Answers
上次活动时间: 2024-7-29

Hello :) This is my first big project using Arduino components, so I don't really understand everything, that's why I encounter so many difficulties. My goal is to send data from my ultrasonic sensor (HC-SR04) to Thingspeak using an Arduino UNO and a GSM SIM800c. Material : Arduino UNO ; GSM SIM 800c shield (https://www.eagle-robotics.com/accueil/257-shield-sim800c-arduino.html) ; Ultrasonic sensor (HC-SR04) ; Cables for my ultrasonic sensor ; Cable to connect my Arduino to my computer. I want to send data to Thinspeak from everywhere, so I can't use Wifi. I found a solution on google : https://github.com/707amitkumar/Send-Data-on-cloud-using-gsm-800c/blob/main/gsmangthingspeak.txt In order to send data to my channel on thingspeak, I did use the code mentionned on the link and I just changed the part concerning the data to send (because I want to send data from my ultrasonic sensor) : #include <SoftwareSerial.h> SoftwareSerial gprsSerial(7,8); #include <String.h> #include <HCSR04.h> const int trigPin = 2 ; const int echoPin = 3 ; UltraSonicDistanceSensor distanceSensor(trigPin, echoPin) ; void setup() { gprsSerial.begin(9600); // the GPRS baud rate Serial.begin(9600); // the GPRS baud rate delay(1000); } void loop() { float distance = distanceSensor.measureDistanceCm(); Serial.print("Distance = "); Serial.print(distance); Serial.println(" cm"); if (gprsSerial.available()) Serial.write(gprsSerial.read()); gprsSerial.println("AT"); delay(1000); gprsSerial.println("AT+CPIN?"); delay(1000); gprsSerial.println("AT+CREG?"); delay(1000); gprsSerial.println("AT+CGATT?"); delay(1000); gprsSerial.println("AT+CIPSHUT"); delay(1000); gprsSerial.println("AT+CIPSTATUS"); delay(2000); gprsSerial.println("AT+CIPMUX=0"); delay(2000); ShowSerialData(); gprsSerial.println("AT+CSTT=\"tango.lu\"");//start task and setting the APN, delay(1000); ShowSerialData(); gprsSerial.println("AT+CIICR");//bring up wireless connection delay(3000); ShowSerialData(); gprsSerial.println("AT+CIFSR");//get local IP adress delay(2000); ShowSerialData(); gprsSerial.println("AT+CIPSPRT=0"); delay(3000); ShowSerialData(); gprsSerial.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",\"80\"");//start up the connection delay(6000); ShowSerialData(); gprsSerial.println("AT+CIPSEND");//begin send data to remote server delay(4000); ShowSerialData(); String str="GET https://api.thingspeak.com/update?api_key=F2WFEAUL58M062LM&field1=0" + String(distance) ; Serial.println(str); gprsSerial.println(str);//begin send data to remote server delay(4000); ShowSerialData(); gprsSerial.println((char)26);//sending delay(5000); //waitting for reply, important the time is base on the condition of internet gprsSerial.println(); ShowSerialData(); gprsSerial.println("AT+CIPSHUT"); //close the connection delay(100); ShowSerialData(); } void ShowSerialData() { while(gprsSerial.available()!=0) Serial.write(gprsSerial.read()); delay(5000); } When I run this code to my Arduino, I notice 2 problems : The piece of information is "sent" to my Thingspeak Channel but it doesn't match with the data sent from my sensors (It always show "0" on Thingspeak while the sensor sends a positive value : 2. I can notice that my code doesn't run as well as expected because the Serial Monitor dislay this : I really don't kow what to do... And I thank you in advance for any help you may give me. I hope my english is not so bad and you cand understand me :) I wish you a good day, Cécilia.
titus in Discussions
上次活动时间: 2023-12-6

Am running multiple sensors in the field producing strings of data then sending them to a node. The node is an Arduino Uno on which SIM 800 is attached for internet connectivity. After computation, the result is several strings that i want to display to things speak. The code i have so far can only upload numerical data. Am in need of help to display these strings in Thingsspeak.Help me. How to display Strings in Thingspeak using SIM800 and Arduino Uno You can write string data to ThingSpeak just as you write numrical data. The automatic field plots wont show it, so you can write that string data to the status field, and enable the status display in your channel settings. Or create a custom MATLAB visualization to show the text read from any field. To create the visualization, you can use thingSpeakRead, then figure, then the text function, or various other methods. sim 800 sim800 arduino uno
farhan in MATLAB Answers
上次活动时间: 2022-11-19

function varargout = Program_Gui_Project(varargin) % PROGRAM_GUI_PROJECT MATLAB code for Program_Gui_Project.fig % PROGRAM_GUI_PROJECT, by itself, creates a new PROGRAM_GUI_PROJECT or raises the existing % singleton*. % % H = PROGRAM_GUI_PROJECT returns the handle to a new PROGRAM_GUI_PROJECT or the handle to % the existing singleton*. % % PROGRAM_GUI_PROJECT('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in PROGRAM_GUI_PROJECT.M with the given input arguments. % % PROGRAM_GUI_PROJECT('Property','Value',...) creates a new PROGRAM_GUI_PROJECT or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Program_Gui_Project_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Program_Gui_Project_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help Program_Gui_Project % Last Modified by GUIDE v2.5 18-Oct-2022 11:00:27 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Program_Gui_Project_OpeningFcn, ... 'gui_OutputFcn', @Program_Gui_Project_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before Program_Gui_Project is made visible. function Program_Gui_Project_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to Program_Gui_Project (see VARARGIN) % Choose default command line output for Program_Gui_Project handles.output = hObject; % Update handles structure guidata(hObject, handles); movegui(hObject,'center'); % UIWAIT makes Program_Gui_Project wait for user response (see UIRESUME) % uiwait(handles.figure1); clear all; global a; a = arduino('COM4','Uno'); configurePin(a,'D7','DigitalOutput'); configurePin(a,'D8','DigitalOutput'); % --- Outputs from this function are returned to the command line. function varargout = Program_Gui_Project_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % memanggil menu "browse file" [nama_file, nama_folder] = uigetfile('*.jpg'); %jika ada nama file yang dipilih maka akan mengeksekusi perintah di bawah %ini if ~isequal(nama_file,0) % membaca file citra rgb Img = imread(fullfile(nama_folder,nama_file)); % menampilkan citra rgb pada axes axes(handles.axes1) imshow(Img) title('Citra RGB') %menampilkan nama file pada edit text set(handles.edit1,'String',nama_file) %menyimpan variabel Img pada lokasi handles agar dapat dipanggil oleh %pushbutton yang lain handles.Img = Img; guidata(hObject, handles) else % jika tidak ada nama file yang dipilih maka akan kembali return end % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % memanggil variabel Img yg ada dilokasi handles Img = handles.Img; % melakukan konversi citra rgb menjadi citra grayscale Img_gray = rgb2gray(Img); %figure, imshow(Img_gray) % melakukan konversi citra grayscale menjadi citra biner bw = imbinarize(Img_gray); % figure, imshow(bw) % melakukan operasi komplemen bw = imcomplement(bw); % figure, imshow(bw) % melakukan operasi morfologi filling holes bw = imfill(bw,'holes'); %menampilkan citra biner pada axes axes(handles.axes2) imshow(bw) title('Citra Biner') %menyimpan variabel bw pada lokasi handles agar dapat dipanggil oleh %pushbutton yang lain handles.bw = bw; guidata(hObject, handles) % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % memanggil variabel Img dan bw yang ada di lokasi handles Img = handles.Img; bw = handles.bw; % ekstraksi ciri % melakukan konversi citra rgb menjadi citra hsv HSV = rgb2hsv(Img); % figure, imshow(HSV) % mengekstrak komponen h, s, dan v pada citra hsv H = HSV(:,:,1); %hue S = HSV(:,:,2); % Saturation V = HSV(:,:,3); % Value % menambah nilai pixel background menjadi nol H(~bw) = 0; S(~bw) = 0; % menghitung nilai rat2 h,s, danv Hue = sum(sum(H))/sum(sum(bw)); Saturation = sum(sum(S))/sum(sum(bw)); Value = sum(sum(V))/sum(sum(bw)); % menghitung luas objek Luas = sum(sum(bw)); % mengisi variabel ciri_latih dengan ciri hasil ekstraksi ciri_uji(1,1) = Hue; ciri_uji(1,2) = Saturation; ciri_uji(1,3) = Value; ciri_uji(1,4) = Luas; % menampilkan ciri hasil ekstraksi pada tabel ciri_tabel = cell(4,2); ciri_tabel{1,1} = 'Hue'; ciri_tabel{2,1} = 'Saturation'; ciri_tabel{3,1} = 'Value'; ciri_tabel{4,1} = 'Luas'; ciri_tabel{1,2} = num2str(Hue); ciri_tabel{2,2} = num2str(Saturation); ciri_tabel{3,2} = num2str(Value); ciri_tabel{4,2} = num2str(Luas); set(handles.uitable1,'Data',ciri_tabel,'RowName',1:4) %menyimpan variabel ciri_uji pada lokasi handles agar dapat dipanggil oleh %pushbutton yang lain handles.ciri_uji = ciri_uji; guidata(hObject, handles) % --- Executes on button press in pushbutton4. function pushbutton4_Callback(hObject, eventdata, handles) % hObject handle to pushbutton4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % memanggil ciri_uji yang ada di lokasi handles ciri_uji = handles.ciri_uji; % memanggil model naive bayes hasil pelatihan load Mdl % membaca kelas keluaran hasil pengujian hasil_uji = predict(Mdl,ciri_uji); % menampilkan kelas keluaran pengujian set(handles.edit2,'String',hasil_uji{1}) function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit1 as text % str2double(get(hObject,'String')) returns contents of edit1 as a double % --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit2_Callback(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit2 as text % str2double(get(hObject,'String')) returns contents of edit2 as a double % --- Executes during object creation, after setting all properties. function edit2_CreateFcn(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in pushbutton5. function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % mereset tampilan GUI set(handles.edit1,'String',[]) set(handles.edit2,'String',[]) axes(handles.axes1) cla reset set(gca,'XTick',[]) set(gca,'YTick',[]) axes(handles.axes2) cla reset set(gca,'XTick',[]) set(gca,'YTick',[]) set(handles.uitable1,'Data',[],'RowName',{'' '' ''}) % --- Executes on button press in pushbutton6. function pushbutton6_Callback(hObject, eventdata, handles) global a; writeDigitalPin(a, 'D7', 1); writeDigitalPin(a, 'D8', 1); % hObject handle to pushbutton6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in pushbutton7. function pushbutton7_Callback(hObject, eventdata, handles) global a; writeDigitalPin(a, 'D7', 0); writeDigitalPin(a, 'D8', 0); % hObject handle to pushbutton7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
Azad Sheikh in MATLAB Answers
上次活动时间: 2022-10-20

Just tried testing esp32 with sim800L on ThingSpeak free channel. Not sure why getting the "http error code 0" because the channel values are getting inserted with new values. It is functioning, but, would be helpful if someone could point out why the http error code 0 is returned ? int i = ThingSpeak.writeField(myBlowerChannel, 1, temp, myBlowerKey); value of 'i' is coming '0' but the temp data is getting inserted
emmanuel jallas in MATLAB Answers
上次活动时间: 2022-6-2

Hello to everyone. I will be very gratefull for support and knowledge sharing with AT commands and troubleshooting knowledge with hardware setup and software. Hardware context : Arduino Uno, SIM800F GSM shield , USB connection and power, Rx -Tx GSM connection strapped on Software Serial Concerning SIM card. Inserted on a mobile phone, can send and receive SMS and phone communications. Data plan available. Software context : I'm using Serial monitor to send AT commands and receive answers. Aim : to follow manually the proper AT sequence to send one piece of data to one field of one channel. Code : [code] // Sending AT commands via Serial Monitor interface #include<SoftwareSerial.h> SoftwareSerial mySerial(2,3); // setting up GSM serial communication void setup() { digitalWrite(8, HIGH); // Switching on GSM shield delay(1100); digitalWrite(8,LOW); mySerial.begin(9600); Serial.begin(9600); Serial.println("Type AT command :"); } void loop() { if (mySerial.available()) Serial.write(mySerial.read()); if (Serial.available()) mySerial.write(Serial.read()); } [/code] Setup : AT returns OK, SMS ready, CALL ready AT+CPIN? returns ready As far I understand the proper sequence of AT commands to connect device to thingspeak server and send data should be this : AT // is SIM800F ready ? good return is : OK AT+CGREG? // is SIM800F registered on GPRS provider network ? good return is : +CGREG: 0,1 (edited) AT+CGATT? // is GPRS attached or not ? good return is : +CGATT: 1 AT+CIPSHUT // resets previous IP session if any. good return is : SHUT OK AT+CIPSTATUS // Check if IP stack is intitalized. good return is : STATE: IP INITIAL AT+CIPMUX=0 // Sets single connection mode. good return is : OK AT+CSTT="APN","","" // Starts task. good return is : OK AT+CIPSTATUS // Not needed but for troubleshooting Check IP status. good return is : STATE: IP START AT+CIICR // Brings up wireless connection. good return is : OK and quick flashing led (edited) AT+CIPSTATUS // Not needed but for troubleshooting Check IP status. good return is : STATE: IP GPRSACT (edited) AT+CIFSR // Gets local IP adress. good return is : anything else than "0.0.0.0" AT+CIPSTART="TCP", "api.thingspeak....","80" // Starts connection with TCP protocol, TCP, domain name, port. good return is : CONNECT OK AT+CIPSEND // Data sending request. good return is : > > data string // Sends data to the proper field and channel >#026 // Ctrl+Z input to indicate the end of data AT+CIPSHUT // Shuts down UDP context. good return is : SHUT OK At this time : AT+CGREG? is returning : +CGREG: 1,0 which states : network registration is enabled, device is not registered and searching for operator's network (edited) AT+CGATT? is returning : 0, which states GPRS is detached AT+CIICR is returning +PDP: DEACT, ERROR Question : What may prevent network registration and getting a +CGREG: 0,1 return ? (edited) How can I troubleshoot and assess actual situation ? Thank you for your insights.
tasya thifali in MATLAB Answers
上次活动时间: 2022-6-1

I'm using sim800l and arduino uno for monitoring battery. The code has no error, but data not show in thingspeak. this is the code: #include <SoftwareSerial.h> #include <String.h> SoftwareSerial SIM800L(6,7); //Serial SIM800L pin String Write_API_key = "xxxxxxxxxxxxxxxx"; //Thingspeak Write API Key String apn = "internet"; int analogPin = A0; // pin arduino yang terhubung dengan pin S modul sensor tegangan float Vmodul = 0.0; float hasil = 0.0; float R1 = 10000.0; //10k float R2 = 220.0; //220 ohm resistor, float value = 0.0; int persen = 0; void setup(){ Serial.begin(115200); SIM800L.begin(9600); pinMode(analogPin,INPUT); Serial.println("SIM800L GPRS Test"); delay(2000); } void loop(){ SetupModule(); SIM800L.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",\"80\""); delay(3000); ShowSerialData(); SIM800L.println("AT+CIPSEND"); delay(2000); Serial.println(); ShowSerialData(); ReadSensor(); String str="GET https://api.thingspeak.com/update?api_key="+Write_API_key+"&field1=" + String(hasil) +"&field2="+String(persen); Serial.println(str); delay(2000); SIM800L.println(str); delay(4000); ShowSerialData(); SIM800L.println((char)26); delay(4000); SIM800L.println(); ShowSerialData(); SIM800L.println("AT+CIPSHUT");//close the connection delay(500); ShowSerialData(); str=""; //total delay looping 50s delay(10000); //add 10s for 60s total delay looping } void ReadSensor(){ value = analogRead(analogPin); Vmodul = (value * 5) / 1024.0; hasil = Vmodul / (R2/(R1+R2)); persen = (hasil/60)*100; Serial.print("\t Tegangan Pembagi = "); Serial.print(Vmodul,2); Serial.print("volt"); Serial.print("\t Hasil pengukuran asli = "); Serial.print(hasil,1); Serial.println("volt"); Serial.print("\t Persentase baterai = "); Serial.print(persen); Serial.println("%"); } void SetupModule(){ if (SIM800L.available())Serial.write(SIM800L.read()); SIM800L.println("AT"); delay(1000); SIM800L.println("AT+CPIN?"); delay(1000); SIM800L.println("AT+CREG?"); delay(1000); SIM800L.println("AT+CGATT?"); delay(1000); SIM800L.println("AT+CIPSHUT");delay(1000); SIM800L.println("AT+CIPSTATUS"); delay(2000); SIM800L.println("AT+CIPMUX=0"); delay(2000); //setting the APN, SIM800L.println("AT+CSTT=\""+apn+"\"");delay(1000); ShowSerialData(); SIM800L.println("AT+CIICR"); delay(2000); ShowSerialData(); //get local IP adress SIM800L.println("AT+CIFSR"); delay(2000); ShowSerialData(); SIM800L.println("AT+CIPSPRT=0");delay(2000); ShowSerialData(); } void ShowSerialData(){ while(SIM800L.available()!=0) Serial.write(SIM800L.read()); delay(2000); }
Raghunath H in MATLAB Answers
上次活动时间: 2021-7-30

I am working on a project to send GPS data from a Neo 6M GPS module connected to TTGO board, to Thingspeak and Blynk using the SIM800L module on the TTGO. For this i have combined two sketches avaiable on the internet.(Thank you to original coders) The first sketch sends GPS Data to Blynk using SIM800L. (Using ESP32 TTGO board) The second sketch sends GPS data to Thingspeak via Wifi. (Using ESP8266) So I combined the two sketches with a bit of editing to achieve what i want. However, the code is not compiling and unable to upload to the TTGO board. I am sure in the cut and paste of sketches i might have made some errors. I am just a newbie and just tinkering with the code. The error is : no matching function for call to 'ThingSpeakClass::begin(ThingSpeakClass&)' Can anyone please point out the error and correct it. Thanks /* GPS Tracker With SIM. Uploading data to Blynk APP and Thingspeak. * */ // TTGO T-Call pin definitions #define MODEM_RST 5 #define MODEM_PWKEY 4 #define MODEM_POWER_ON 23 #define MODEM_TX 27 #define MODEM_RX 26 #define I2C_SDA 21 #define I2C_SCL 22 #include <TinyGPS++.h> //https://github.com/mikalhart/TinyGPSPlus #include <AceButton.h> // https://github.com/bxparks/AceButton #define BLYNK_PRINT Serial #define BLYNK_HEARTBEAT 30 #define TINY_GSM_MODEM_SIM800 #define ThingSpeak client #include <TinyGsmClient.h> // https://github.com/vshymanskyy/TinyGSM #include <BlynkSimpleSIM800.h> //https://github.com/blynkkk/blynk-library #include <Wire.h> #include "utilities.h" #include "ThingSpeak.h" // Variables for storing GPS Data float latitude; float longitude; float speed; float satellites; String direction; // Set serial for GPS Module #define SerialMon Serial // Hardware Serial for builtin GSM Module #define SerialAT Serial1 //const char apn[] = "www"; const char apn[] = "airtelgprs.com"; const char user[] = ""; const char pass[] = ""; // You should get Auth Token in the Blynk App. // Go to the Project Settings (nut icon). const char auth[] = "2xxxxxxxkbBOa3ZlPf"; unsigned long myChannelNumber = 1xxxxxx30; const char * myWriteAPIKey = "XxxxxxxxxxxAF"; static const uint32_t GPSBaud = 9600; TinyGPSPlus gps; WidgetMap myMap(V0); BlynkTimer timer; TinyGsm modem(SerialAT); unsigned int move_index = 1; void setup() { // Set console baud rate Serial.begin(115200); delay(10); // Keep power when running from battery Wire.begin(I2C_SDA, I2C_SCL); bool isOk = setPowerBoostKeepOn(1); SerialMon.println(String("IP5306 KeepOn ") + (isOk ? "OK" : "FAIL")); // Set-up modem reset, enable, power pins pinMode(MODEM_PWKEY, OUTPUT); pinMode(MODEM_RST, OUTPUT); pinMode(MODEM_POWER_ON, OUTPUT); pinMode(SMS_Button, INPUT); pinMode(Call_Button, INPUT); digitalWrite(MODEM_PWKEY, LOW); digitalWrite(MODEM_RST, HIGH); digitalWrite(MODEM_POWER_ON, HIGH); // Set GSM module baud rate and UART pins SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX); delay(3000); // Restart takes quite some time // To skip it, call init() instead of restart() SerialMon.println("Initializing modem..."); modem.restart(); String modemInfo = modem.getModemInfo(); SerialMon.print("Modem: "); SerialMon.println(modemInfo); // Unlock your SIM card with a PIN //modem.simUnlock("1234"); SerialMon.print("Waiting for network..."); if (!modem.waitForNetwork(240000L)) { SerialMon.println(" fail"); delay(10000); return; } SerialMon.println(" OK"); if (modem.isNetworkConnected()) { SerialMon.println("Network connected"); } SerialMon.print(F("Connecting to APN: ")); SerialMon.print(apn); if (!modem.gprsConnect(apn, user, pass)) { SerialMon.println(" fail"); delay(10000); return; } SerialMon.println(" OK"); Blynk.begin(auth, modem, apn, user, pass); timer.setInterval(5000L, checkGPS); ThingSpeak.begin(client); ///////////////////////////////////////////// //Error on this line } void checkGPS() { if (gps.charsProcessed() < 10) { Blynk.virtualWrite(V4, "GPS ERROR"); } } void loop() { while (Serial.available() > 0) { if (gps.encode(Serial.read())) displayInfo(); } Blynk.run(); timer.run(); sms_button.check(); call_button.check(); } void displayInfo() { if (gps.location.isValid()) { double latitude = (gps.location.lat()); double longitude = (gps.location.lng()); double speed = (gps.speed.kmph()); float satellites =(gps.satellites.value()); String direction = TinyGPSPlus::cardinal(gps.course.value()); String latbuf; latbuf += (String(latitude, 6)); Serial.println(latbuf); String lonbuf; lonbuf += (String(longitude, 6)); Serial.println(lonbuf); String speedbuf; speedbuf += (float(speed)); Serial.println(speedbuf); String dirbuf; dirbuf += (String(direction)); Serial.println(dirbuf); float satbuf; satbuf += (float(satellites)); Serial.println(satbuf); ThingSpeak.setField(1, latbuf); ThingSpeak.setField(2, lonbuf); ThingSpeak.setField(3, speedbuf); ThingSpeak.setField(4, dirbuf); ThingSpeak.setField(5, satbuf); ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); delay(20000); } else { Serial.print(F("INVALID")); } Serial.print(F(" Date/Time: ")); if (gps.date.isValid()) { Serial.print(gps.date.month()); Serial.print(F("/")); Serial.print(gps.date.day()); Serial.print(F("/")); Serial.print(gps.date.year()); } else { Serial.print(F("INVALID")); } Serial.print(F(" ")); if (gps.time.isValid()) { if (gps.time.hour() < 10) Serial.print(F("0")); Serial.print(gps.time.hour()); Serial.print(F(":")); if (gps.time.minute() < 10) Serial.print(F("0")); Serial.print(gps.time.minute()); Serial.print(F(":")); if (gps.time.second() < 10) Serial.print(F("0")); Serial.print(gps.time.second()); Serial.print(F(".")); if (gps.time.centisecond() < 10) Serial.print(F("0")); Serial.print(gps.time.centisecond()); } else { Serial.print(F("INVALID")); } Serial.println(); } { if (gps.location.isValid() ) { latitude = (gps.location.lat()); //Storing the Lat. and Lon. longitude = (gps.location.lng()); Blynk.virtualWrite(V1, String(latitude, 6)); Blynk.virtualWrite(V2, String(longitude, 6)); myMap.location(move_index, latitude, longitude, "GPS_Location"); speed = gps.speed.kmph(); //get speed Blynk.virtualWrite(V3, speed); direction = TinyGPSPlus::cardinal(gps.course.value()); // get the direction Blynk.virtualWrite(V4, direction); satellites = gps.satellites.value(); //get number of satellites Blynk.virtualWrite(V5, satellites); } }
Johnson Isaac in MATLAB Answers
上次活动时间: 2020-4-26

Pls I need help to read my channel field last value (1 or 0) and in turn switch on a relay connected to my arduino pin using sim800l. I don't know how to go about the code for it. Anyone with a link to an example or a guide pls. My channel field is been updated with a "1" or "0" from my mit app inventor mobile app. In return I want to turn on a relay on/off when this field is updated by using sim800l to be checking the field last value

关于 ThingSpeak

The community for students, researchers, and engineers looking to use MATLAB, Simulink, and ThingSpeak for Internet of Things applications. You can find the latest ThingSpeak news, tutorials to jump-start your next IoT project, and a forum to engage in a discussion on your latest cloud-based project. You can see answers to problems other users have solved and share how you solved a problem.