標(biāo)題:
關(guān)于利用GSM模塊上傳三路溫濕度數(shù)據(jù)到onenet 沒任何反應(yīng),僅僅可以發(fā)短信
[打印本頁]
作者:
臉盲啊
時(shí)間:
2020-4-29 21:30
標(biāo)題:
關(guān)于利用GSM模塊上傳三路溫濕度數(shù)據(jù)到onenet 沒任何反應(yīng),僅僅可以發(fā)短信
利用GSM模塊上傳數(shù)據(jù)到onenet,沒任何反應(yīng),僅僅可以發(fā)短信。
程序:
#include "reg52.h"
#include "type.h"
#include <string.h>
#include <stdio.h>
bit flag;
uchar model=0; //模式
uchar temp1H=35; //上限值
uchar temp2H=35; //上限值
uchar temp3H=35; //上限值
uchar hum1H=50; //上限值
uchar hum2H=50; //上限值
uchar hum3H=50; //上限值
uchar temp_L=10;
uchar date[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
unsigned char temp1=0,temp2=0,temp3=0,hum1=0,hum2=0,hum3=0;
#define SEND_MESSA_TO_YOUR "at+cmgs=\"185*****436\"\r\n" //填入你手上的手機(jī)號(hào)碼 不是板子的
#include "LCD1602.H"
sbit set=P1^6;
sbit add=P3^5;
sbit min=P3^4;
sbit beep=P3^6;
sbit led1=P1^2;
sbit led2=P1^1;
/***********模擬開關(guān)*********************/
sbit CS_4052=P1^0;
sbit B_4052=P1^1;
sbit A_4052=P1^2;
uchar fen=0; //定時(shí)發(fā)送短信計(jì)時(shí)
bit sendFlag=0; //發(fā)送短信標(biāo)志
void delay1ms(unsigned int ms)//延時(shí)1毫秒(不夠精確的)
{unsigned int i,j;
for(i=0;i<ms;i++)
for(j=0;j<100;j++);
}
void Uart_Send(uchar dat) //發(fā)送一字節(jié)
{
SBUF=dat;
while(!TI);
TI=0;
}
//發(fā)送一串字符到串口
void Uart_Sends(char* data_at)
{
unsigned char cnt=0;
while(*(data_at+cnt)) //判斷一串?dāng)?shù)據(jù)是否結(jié)束
{
Uart_Send(*(data_at+cnt));
cnt++;
}
}
void select(uchar num)
{
if(num==1) //上位機(jī)串口使能
{
CS_4052=0;
B_4052=0;
A_4052=0;
}
else if(num==2) //CC2530串口使能
{
CS_4052=0;
B_4052=0;
A_4052=1;
}
else if(num==3) //wifi串口使能
{
CS_4052=0;
B_4052=1;
A_4052=0;
}
}
//發(fā)送短信函數(shù)
void Send_SMS(void)
{
uchar yy=1;
select(1); //GSM模塊串口使能
delay1ms(100);
Uart_Sends("AT+CMGF=1\r");//設(shè)置中文方式發(fā)送
delay1ms(800);
delay1ms(1000);
Uart_Sends(SEND_MESSA_TO_YOUR);
delay1ms(1000);
switch (yy)
{
case 1 : Uart_Sends("wendu1=\r\n");
Uart_Send(temp1/10+0x30);
Uart_Send(temp1%10+0x30);
Uart_Sends(",wendu2=");
Uart_Send(temp2/10+0x30);
Uart_Send(temp2%10+0x30);
Uart_Sends(",wendu3=");
Uart_Send(temp3/10+0x30);
Uart_Send(temp3%10+0x30);
Uart_Sends("\r\nshidu1=\r\n");
Uart_Send(hum1/10+0x30);
Uart_Send(hum1%10+0x30);
Uart_Sends(",shidu2=");
Uart_Send(hum2/10+0x30);
Uart_Send(hum2%10+0x30);
Uart_Sends(",shidu3=");
Uart_Send(hum3/10+0x30);
Uart_Send(hum3%10+0x30);
Uart_Sends("\r\n");
if(temp1>temp1H)
{
Uart_Sends("wendu1 Warning!!!\r\n");
}
if(temp2>temp2H)
{
Uart_Sends("wendu2 Warning!!!\r\n");
}
if(temp3>temp3H)
{
Uart_Sends("wendu3 Warning!!!\r\n");
}
if(hum1>hum1H)
{
Uart_Sends("hum1 Warning!!!\r\n");
}
if(hum2>hum2H)
{
Uart_Sends("hum2 Warning!!!\r\n");
}
if(hum3>hum3H)
{
Uart_Sends("hum3 Warning!!!\r\n");
}
break; //煙霧報(bào)警
}
Uart_Send(0x1a);//以0x1a來結(jié)束,表示內(nèi)容結(jié)束,發(fā)送短信
}
void key()
{
uchar i=0;
if(!set) //檢測(cè)設(shè)置按鍵
{
while(!set);
model++;
if(model==7)
{
model=0;
}
if(model==1)//設(shè)置模式顯示
{
WRITE_LCD1602_COM(0x80);
for(i=0;i<16;i++)
WRITE_LCD1602_DAT(DIS_TAB3[i]);
WRITE_LCD1602_COM(0x80+0x40);
for(i=0;i<16;i++)
WRITE_LCD1602_DAT(DIS_TAB4[i]);
WRITE_LCD1602_COM(0x80+0x40+9);
}
else if(model==0)//正常模式顯示
{
WRITE_LCD1602_COM(0x80);
for(i=0;i<16;i++)
WRITE_LCD1602_DAT(DIS_TAB1[i]);
WRITE_LCD1602_COM(0x80+0x40);
for(i=0;i<16;i++)
WRITE_LCD1602_DAT(DIS_TAB2[i]);
WRITE_LCD1602_COM(0x80+0x40+9);
}
}
else if(!add)
{
while(!add);
switch(model)
{
case 1: if(temp1H<90) temp1H++; break;
case 2: if(temp2H<90) temp2H++; break;
case 3: if(temp3H<90) temp3H++; break;
case 4: if(hum1H<90) hum1H++; break;
case 5: if(hum2H<90) hum2H++; break;
case 6: if(hum3H<90) hum3H++; break;
default:break;
}
}
else if(!min)
{
while(!min);
switch(model)
{
case 1: if(temp1H>0) temp1H--; break;
case 2: if(temp2H>0) temp2H--; break;
case 3: if(temp3H>0) temp3H--; break;
case 4: if(hum1H>0) hum1H--; break;
case 5: if(hum2H>0) hum2H--; break;
case 6: if(hum3H>0) hum3H--; break;
default:break;
}
}
}
void beeps()
{
static uchar count;
count++;
if(count<20)
beep=0;
else if(count<40)
beep=1;
else
count=0;
}
void control()//報(bào)警檢測(cè)控制
{
static uchar flagsend=0;
if((temp1>temp1H)||(temp2>temp2H)||(temp3>temp3H)||
(hum1>hum1H)||(hum2>hum2H)||(hum3>hum3H)) //溫度控制
{
beeps(); // 蜂鳴器報(bào)警
if(flagsend==0)
{
flagsend=1;
Send_SMS();
}
}
else
{
flagsend=0;
beep=1;// 關(guān)閉蜂鳴器報(bào)警
}
}
void rec_cc2530data()
{
select(2); //選通 cc2530 串口
ES=1; //串口接收中斷
if(date[0]==0x55)
{
date[0]=0;
if((date[1]==1)&&(date[2]+date[3]==date[4])) //第一路 數(shù)據(jù)
{
date[1]=0;
temp1=date[2];
hum1=date[3];
}
if((date[1]==2)&&(date[2]+date[3]==date[4])) //第二路
{
date[1]=0;
temp2=date[2];
hum2=date[3];
}
if((date[1]==3)&&(date[2]+date[3]==date[4])) //第三路
{
date[1]=0;
temp3=date[2];
hum3=date[3];
}
}
}
void GsmInit()
{
select(1); //打開上位機(jī)串口
Uart_Sends("AT+CIPCLOSE\r\n");
delay1ms(1000);
Uart_Sends("AT+CIPSHUT\r\n");
delay1ms(1000);
Uart_Sends("AT+CREG?\x00D\x00A");
delay1ms(1000);
Uart_Sends("AT+CGATT=1\r\n");
delay1ms(1000);
Uart_Sends("AT+CIPRXGET=0\r\n");
delay1ms(1000);
Uart_Sends("AT+CSTT=CMIOT\r\n");
Uart_Sends("AT+CIICR\r\n");
delay1ms(1000);
Uart_Sends("AT+CIPRXGET=0\r\n");
delay1ms(1000);
Uart_Sends("AT+CIPQRCLOSE=1\r\n");
delay1ms(1000);
Uart_Sends("AT+CIPMODE=0\r\n");
delay1ms(1000);
Uart_Sends("AT+CIPSTART=\"TCP\",\"183.230.40.33\",\"80\"\r\n");//此處修改你建立服務(wù)器的IP,服務(wù)器端口號(hào)8080
delay1ms(1000);
// Uart_Sends("AT+CIPSEND\r\n");
// delay1ms(1000);
//SendString("POST /devices/1100286/datapoints?type=3 HTTP/1.1\r\n");
Uart_Sends("POST /devices/594614665/datapoints?type=3 HTTP/1.1\r\n"); //將數(shù)字修改為自己的設(shè)備id)
delay1ms(1000);
Uart_Sends("Host:api.heclouds點(diǎn)com\r\n");
delay1ms(1000);
//SendString("api-key:DcQ2NF=70s3j3=mlsFXfPod1kaY=\r\n");
Uart_Sends("api-key: RJPjiEVRqddktp2OP5mbn=qiWWI=\r\n"); //這里填寫自己的API-key
delay1ms(1000);
}
void SendGprsData(uchar *sendbuf) //ADD
{
unsigned char lenbuf[4];
select(1);
delay1ms(1000);
Uart_Sends("AT+CIPSEND=");
sprintf(lenbuf,"%d",strlen(sendbuf));
Uart_Sends(lenbuf);
Uart_Sends("\r\n");
delay1ms(1000);
Uart_Sends(sendbuf);
Uart_Sends(0x1a);//ADD
delay1ms(1000);
}
void Timer0Init(void) //50毫秒@11.0592MHz
{
TMOD &= 0xF0; //設(shè)置定時(shí)器模式
TMOD |= 0x01; //設(shè)置定時(shí)器模式
TL0 = 0x00; //設(shè)置定時(shí)初值
TH0 = 0x4C; //設(shè)置定時(shí)初值
TF0 = 0; //清除TF0標(biāo)志
TR0 = 1; //定時(shí)器0開始計(jì)時(shí)
ET0=1;
}
bit SendGprsFlag=0,GsmInitFlag=0;
idata unsigned char SendBuf[26];
void main()
{
init_1602();
TMOD=0x20; // T1定時(shí)方式2
SCON=0x40;//串行工作 方式1
PCON=0x00; //不加倍
TH1=TL1=0xfd; //定時(shí)器1賦初值 保證波特率9600
TR1=1; //開定時(shí)器1
REN=1; //允許串口接收
ES=1; //打開串口中斷
EA=1; //開總中?
Timer0Init();
GsmInit(); //sim800初始化 ******ADD
while(1)
{
control(); //控制
key(); //按鍵功能
if(SendGprsFlag==1) //1一分鐘向GPRS發(fā)送一次數(shù)據(jù)
{
SendGprsFlag=0; //ADD
if(GsmInitFlag==0)
{
GsmInitFlag=1;
GsmInit(); //H1:50%,
} //T1:23C,
sprintf(SendBuf,"T1:%2dC,T2:%2dC,T2:%2dC\r\n",(unsigned int)temp1,(unsigned int)temp2,(unsigned int)temp3);
SendGprsData(SendBuf);
delay1ms(1000);
sprintf(SendBuf,"H1:%2%%,H2:%2%%,H3:%2%%\r\n",(unsigned int)hum1,(unsigned int)hum2,(unsigned int)hum3);
SendGprsData(SendBuf);
}
if(sendFlag==0)
{
sendFlag=1; //代表已經(jīng)發(fā)過一次,不在發(fā)了
Send_SMS(); //發(fā)送短信
}
rec_cc2530data();
delay1ms(50);
display();
}
}
void serial()interrupt 4 //串口中斷服務(wù)函數(shù)
{
static uchar j;
if(!RI);
RI=0; //清楚接收完畢標(biāo)志
date[j]=SBUF;
if(date[0]==0x55) //判斷接收到的第一位為傳感器所發(fā)數(shù)據(jù)
j++;
else
j=0;
if(j==5) //接收傳感器所發(fā)數(shù)據(jù)字節(jié)
j=0;
}
void timer0() interrupt 1 //50ms
{
static uchar count=0,miao=0;
TL0 = 0x00; //設(shè)置定時(shí)初值
TH0 = 0x4C; //設(shè)置定時(shí)初值
count++;
if(count>20)
{
count=0;
miao++;
if(miao>60)
{
miao=0;
fen++;
if(fen>=1)
{
fen=0;
sendFlag=0;
}
}
}
}
復(fù)制代碼
接收機(jī)-程序.zip
2020-4-29 21:30 上傳
點(diǎn)擊文件名下載附件
102.51 KB, 下載次數(shù): 9
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1